﻿using System;
using System.Xml;
using System.Data;
using System.IO;
using System.Diagnostics;
using System.Text;
using LibKetoan;

namespace Ketoan
{
	/// <summary>
	/// Summary description for frmReportNguon_class.
	/// </summary>
	public class frmReportNguon_class
	{
		#region Khai bao thanh phan su dung trong class
		bool flag_dsnull;
		string sql="", sql1="";
		System.Data.DataSet ds_Data;
		System.Data.DataSet ds_Data2;
		System.Data.DataSet ds_Data3;
		System.Data.DataSet ds_sdDaunam;
		bool b_dsnull;

		#endregion

		public frmReportNguon_class()
		{
		}	
		
        public System.Data.DataSet SoCai_S3b(LibKetoan.AccessData a,string s_IDtk, string s_sotk,string s_IDlk,string s_Tungay,string s_Denngay,string s_mm,string s_mm1, string s_yy,string s_yyyy,bool b_Checkngay,string s_IDChuong, string s_IDHoatdong,string s_IDNhombc,string s_IDkm,string s_IDkm2,string s_IDkm3,string s_IDkm4,string s_muc,string s_IDdoituong,int i_dkgroup,string s_Tenform)
		{
			string s_DKgroup="";
			if(i_dkgroup!=-1) s_DKgroup=", "+i_dkgroup+" as nhom";
			else s_DKgroup=", -1 as nhom ";				
			
			string s_DKSelectgroup="",s_DKGroupbygroup="",s_DKfrom="";
			switch(i_dkgroup)
			{
				case 0:
					s_DKSelectgroup=" ch.ten as chuong,ch.id as idchuong,";
					s_DKSelectgroup+=" 0 as iddoituong, 0 as idnhombc,0 as idhoatdong, 0 as idmuc, 0 as idkm, 0 as idkm2, 0 as idkm3, 0 as idkm4,";
					s_DKSelectgroup+=" '' as doituong, '' as nhombc,'' as hoatdong, '' as muc, '' as km, '' as km2, '' as km3, '' as km4,";
					s_DKGroupbygroup=" ch.ten,ch.id,";
					s_DKGroupbygroup+=" '', '', '', '', '', '', '','',";
					s_DKGroupbygroup+=" '', '', '', '', '', '', '','',";
					s_DKfrom=" left join "+a.user+".a_dmchuong ch on ct.chuong=ch.id";					
					break;
				case 1:
					s_DKSelectgroup=" dt.tendt as doituong,dt.id as iddoituong,";
					s_DKSelectgroup+=" 0 as idchuong, 0 as idnhombc,0 as idhoatdong, 0 as idmuc, 0 as idkm, 0 as idkm2, 0 as idkm3, 0 as idkm4,";
					s_DKSelectgroup+=" '' as chuong, '' as nhombc,'' as hoatdong, '' as muc, '' as km, '' as km2, '' as km3, '' as km4,";
					s_DKGroupbygroup=" dt.tendt,dt.id,";									
					s_DKGroupbygroup+=" '', '', '', '', '', '', '','',";
					s_DKGroupbygroup+=" '', '', '', '', '', '', '','',";
					s_DKfrom=" left join "+a.user+".a_dmdt dt on ct.madt=dt.id";
					break;
				case 2:
					s_DKSelectgroup=" hd.ten as hoatdong,hd.id as idhoatdong,";
					s_DKSelectgroup+=" 0 as idchuong,0 as iddoituong, 0 as idnhombc,0 as idmuc, 0 as idkm, 0 as idkm2, 0 as idkm3, 0 as idkm4,";
					s_DKSelectgroup+=" '' as chuong,'' as doituong, '' as nhombc,'' as muc, '' as km, '' as km2, '' as km3, '' as km4,";
					s_DKGroupbygroup=" hd.ten,hd.id,";
					s_DKfrom=" left join "+a.user+".a_hoatdong hd on ct.hoatdong=hd.id";
					s_DKGroupbygroup+=" '', '', '', '', '', '', '','',";
					s_DKGroupbygroup+=" '', '', '', '', '', '', '','',";
					break;
				case 3:
					s_DKSelectgroup=" case when(chno.ttk <>' ') then chno.ttk else chco.ttk end as muc,";
					s_DKSelectgroup+=" case when(chno.ttk <>' ') then chno.id else chco.id end as idmuc,";
					s_DKSelectgroup+=" 0 as idchuong,0 as iddoituong, 0 as idnhombc,0 as idhoatdong, 0 as idkm, 0 as idkm2, 0 as idkm3, 0 as idkm4,";
					s_DKSelectgroup+=" '' as chuong,'' as doituong, '' as nhombc,'' as hoatdong, '' as km, '' as km2, '' as km3, '' as km4,";
					s_DKGroupbygroup=" case when(chno.ttk <>' ') then chno.id else chco.id end,";
					s_DKGroupbygroup+=" case when(chno.ttk <>' ') then chno.ttk else chco.ttk end,";
					s_DKGroupbygroup+=" '', '', '', '', '', '', '','',";
					s_DKGroupbygroup+=" '', '', '', '', '', '', '','',";
					s_DKfrom=" left join "+a.user+".a_dmch chco on ctct.mtmco=chco.id";
					s_DKfrom+=" left join "+a.user+".a_dmch chno on ctct.mtmno=chno.id";
					break;
				case 4:
					s_DKSelectgroup=" bc.ten as nhombc,bc.id as idnhombc,";
					s_DKSelectgroup+=" 0 as idchuong, 0 as iddoituong,0 as idhoatdong, 0 as idmuc, 0 as idkm, 0 as idkm2, 0 as idkm3, 0 as idkm4,";
					s_DKSelectgroup+=" '' as chuong, '' as doituong,'' as hoatdong, '' as muc, '' as km, '' as km2, '' as km3, '' as km4,";
					s_DKGroupbygroup=" bc.ten,bc.id,";
					s_DKGroupbygroup+=" '', '', '', '', '', '', '','',";
					s_DKGroupbygroup+=" '', '', '', '', '', '', '','',";
					s_DKfrom="left join "+a.user+".a_dmnhombc bc on ct.idbc=bc.id";
					break;
				case 5:
					s_DKSelectgroup=" case when (kmno.ten <>' ') then kmno.ten else kmco.ten end as km,";
					s_DKSelectgroup+=" case when (kmno.ten <>' ') then kmno.id else kmco.id end as idkm,";
					s_DKSelectgroup+=" 0 as idchuong, 0 as idnhombc,0 as idhoatdong, 0 as idmuc,0 as iddoituong, 0 as idkm2, 0 as idkm3, 0 as idkm4,";
					s_DKSelectgroup+=" '' as chuong, '' as nhombc,'' as hoatdong, '' as muc, '' as doituong, '' as km2, '' as km3, '' as km4,";
					s_DKGroupbygroup=" case when(kmno.ten <>' ') then kmno.ten else kmco.ten end,";
					s_DKGroupbygroup+=" case when(kmno.ten <>' ') then kmno.id else kmco.id end,";
					s_DKGroupbygroup+=" '', '', '', '', '', '', '','',";
					s_DKGroupbygroup+=" '', '', '', '', '', '', '','',";
					s_DKfrom=" left join "+a.user+".a_dmkhoanmuc kmno on ctct.kmno=kmno.id";
					s_DKfrom+=" left join "+a.user+".a_dmkhoanmuc kmco on ctct.kmco=kmco.id";
					break;
				case 6:
					s_DKSelectgroup=" case when (kmno2.ten <>' ') then kmno2.ten else kmco2.ten end as km2,";
					s_DKSelectgroup+=" case when (kmno2.ten <>' ') then kmno2.id else kmco2.id end as idkm2,";
					s_DKSelectgroup+=" 0 as idchuong, 0 as idnhombc,0 as idhoatdong, 0 as idmuc, 0 as idkm, 0 as iddoituong, 0 as idkm3, 0 as idkm4,";
					s_DKSelectgroup+=" '' as chuong, '' as nhombc,'' as hoatdong, '' as muc, '' as km, '' as doituong, '' as km3, '' as km4,";
					s_DKGroupbygroup=" case when(kmno2.ten<>' ') then kmno2.ten else kmco2.ten end,";
					s_DKGroupbygroup+=" case when(kmno2.ten<>' ') then kmno2.id else kmco2.id end,";
					s_DKGroupbygroup+=" '', '', '', '', '', '', '','',";
					s_DKGroupbygroup+=" '', '', '', '', '', '', '','',";
					s_DKfrom=" left join "+a.user+".a_dmkhoanmuc kmno2 on ctct.kmno2=kmno2.id";
					s_DKfrom+=" left join "+a.user+".a_dmkhoanmuc kmco2 on ctct.kmco2=kmco2.id";
					break;
				case 7:
					s_DKSelectgroup=" case when (kmno3.ten<>' ') then kmno3.ten else kmco3.ten end as km3,";
					s_DKSelectgroup+=" case when (kmno3.ten<>' ') then kmno3.id else kmco3.id end as idkm3,";
					s_DKSelectgroup+=" 0 as idchuong, 0 as idnhombc,0 as idhoatdong, 0 as idmuc, 0 as idkm, 0 as idkm2, 0 as iddoituong, 0 as idkm4,";
					s_DKSelectgroup+=" '' as chuong, '' as nhombc,'' as hoatdong, '' as muc, '' as km, '' as km2, '' as doituong, '' as km4,";
					s_DKGroupbygroup=" case when(kmno3.ten<>' ' ) then kmno3.ten else kmco3.ten end,";
					s_DKGroupbygroup+=" case when(kmno3.ten<>' ' ) then kmno3.id else kmco3.id end,";
					s_DKGroupbygroup+=" '', '', '', '', '', '', '','',";
					s_DKGroupbygroup+=" '', '', '', '', '', '', '','',";
					s_DKfrom=" left join "+a.user+".a_dmkhoanmuc kmno3 on ctct.kmno3=kmno3.id";
					s_DKfrom+=" left join "+a.user+".a_dmkhoanmuc kmco3 on ctct.kmco3=kmco3.id";
					break;
				case 8:
					s_DKSelectgroup=" case when (kmno4.ten<>' ') then kmno4.ten else kmco4.ten end as km4,";
					s_DKSelectgroup+=" case when (kmno4.ten<>' ') then kmno4.id else kmco4.id end as idkm4,";
					s_DKSelectgroup+=" 0 as idchuong, 0 as idnhombc,0 as idhoatdong, 0 as idmuc, 0 as idkm, 0 as idkm2, 0 as idkm3, 0 as iddoituong,";
					s_DKSelectgroup+=" '' as chuong, '' as nhombc,'' as hoatdong, '' as muc, '' as km, '' as km2, '' as km3, '' as doituong,";
					s_DKfrom=" left join "+a.user+".a_dmkhoanmuc kmno4 on ctct.kmno4=kmno4.id";	
					s_DKfrom+=" left join "+a.user+".a_dmkhoanmuc kmco4 on ctct.kmco4=kmco4.id";s_DKGroupbygroup=" case when(kmno4.ten<>' ') then kmno4.ten else kmco4.ten end,";
					s_DKGroupbygroup+=" case when(kmno4.ten<>' ') then kmno4.id else kmco4.id end,";
					s_DKGroupbygroup+=" '', '', '', '', '', '', '','',";
					s_DKGroupbygroup+=" '', '', '', '', '', '', '','',";
					break;
				default: 					
					s_DKSelectgroup+=" 0 as idchuong, 0 as idnhombc,0 as idhoatdong, 0 as idmuc, 0 as idkm, 0 as idkm2, 0 as idkm3, 0 as idkm4,0 as iddoituong,";
					s_DKSelectgroup+=" '' as chuong, '' as nhombc,'' as hoatdong, '' as muc, '' as km, '' as km2, '' as km3, '' as km4,'' as doituong,";
					s_DKGroupbygroup+=" '', '', '', '', '', '', '','',";
					s_DKGroupbygroup+=" '', '', '', '', '', '', '','',";
					break;
			}
			

			sql=  "select distinct ct.id, to_char(ct.ngayg,'dd/mm/yyyy') as ngayct,ct.thanggs as thang,";
			sql+=" ct.soctg as soctg, to_char(ct.ngaygs,'dd/mm/yyyy') as ngaygs,dmtkno.stk as tkno, dmtkco.stk as tkco,";
			if(s_Tenform=="SOCAI_S3b")sql+=" ct.noidung as diengiai,";
			else sql+=" nvl(ctct.noidung,ct.noidung) diengiai,";
			sql+=" (case when ctct.tknoa in("+s_IDtk+") then dmtkco.stk else (case when";
			sql+=" ctct.tkcoa in("+s_IDtk+") then dmtkno.stk else '' end) end) tkdoiung,";
			sql+=" sum(case when ctct.tknoa in("+s_IDtk+") then ctct.stien else 0 end) no,";
			sql+=" sum(case when ctct.tkcoa in("+s_IDtk+") then ctct.stien else 0 end) co,";
			sql+=" "+s_DKSelectgroup+"";
			sql+=" 0 luykenam_co, 0 luykenam_no, 0 luykequy_co, 0 luykequy_no,";
			sql+=" 0 sodu_no,0 sodu_co";
			sql+=" "+s_DKgroup+"";
			sql+=" from "+a.user+".a_ct"+s_yy+" ct inner join "+a.user+".a_ctct"+s_yy+" ctct on ct.id=ctct.idct";
			sql+=" left join "+a.user+".a_dmlk lk on ctct.lk=lk.id";
			sql+=" "+s_DKfrom+"";
			sql+=" left join "+a.user+".a_dmtk dmtkno on ctct.tknoa=dmtkno.id";
			sql+=" left join "+a.user+".a_dmtk dmtkco on ctct.tkcoa=dmtkco.id";
			sql+=" where ctct.tonghop=1";		
			if (b_Checkngay) sql+=" and to_date(to_char(ct.ngayg,'dd/mm/yyyy'),'dd/mm/yyyy') between to_date('"+s_Tungay+"','dd/mm/yyyy') and to_date('"+s_Denngay+"','dd/mm/yyyy')";
			else sql+=" and ct.thanggs between '"+s_mm+"' and '"+s_mm1+"'";	
			if (s_IDlk!="") sql+=" and lk.id='"+s_IDlk+"'";
			sql+=" and (ctct.tknoa in("+s_IDtk+") or ctct.tkcoa in("+s_IDtk+"))";
			if(s_IDChuong!="")sql+=" and ct.chuong="+s_IDChuong;
			if(s_IDHoatdong!="")sql+=" and ct.hoatdong="+s_IDHoatdong;
			if(s_IDNhombc!="")sql+=" and ct.idbc="+s_IDNhombc;
			if (s_IDkm!="") sql+=" and (ctct.kmno like '"+s_IDkm+"' or ctct.kmco like '"+s_IDkm+"')";		
			if (s_IDkm2!="") sql+=" and (ctct.kmno2 like '"+s_IDkm2+"' or ctct.kmco2 like '"+s_IDkm2+"'";			
			if (s_IDkm3!="") sql+=" and (ctct.kmno3 like '"+s_IDkm3+"' or ctct.kmco3 like '"+s_IDkm3+"'";			
			if (s_IDkm4!="") sql+=" and (ctct.kmno4 like '"+s_IDkm4+"' or ctct.kmco4 like '"+s_IDkm4+"'";
			if(s_IDdoituong!="")sql+=" and ct.madt="+s_IDdoituong;
			if(s_muc!="")sql+=" and (chno.id in("+s_muc+") or chco.id in ("+s_muc+"))";
			sql+=" group by ";
			sql+=" "+s_DKGroupbygroup+"";
			sql+=" ct.id,ct.ngayg,ct.thanggs,";
			sql+=" ct.soctg, ct.ngaygs,dmtkno.stk, dmtkco.stk,";
			if(s_Tenform=="SOCAI_S3b")sql+=" ct.noidung,";
			else sql+=" nvl(ctct.noidung,ct.noidung),";
			sql+=" (case when ctct.tknoa in("+s_IDtk+") then dmtkco.stk else (case when";
			sql+=" ctct.tkcoa in("+s_IDtk+") then dmtkno.stk else '' end) end)";
			sql+=" order by ct.id,ct.soctg";

			//tinh so du dau ky
			int tuthang = Convert.ToInt32(s_mm);
			int denthang = Convert.ToInt32(s_mm1);	

			string sql_dk = "";
			for(int i = tuthang; i<= denthang ;i++ )
			{				
				sql_dk+=" (select sum(sdco"+i.ToString().PadLeft(2,'0')+") as sodudk_co,";
				sql_dk+=" sum(sdno"+i.ToString().PadLeft(2,'0')+") as sodudk_no,";
				sql_dk+="'"+i.ToString().PadLeft(2,'0')+"' as thang,0 as no,0 as co";
				sql_dk+=" from "+a.user+".a_sd"+s_yy+" a";
				sql_dk+=" where a.stka in ("+s_IDtk+")";
				if(s_IDlk!="")sql_dk+=" and a.lk="+s_IDlk;
				if(s_IDChuong!="")sql_dk+=" and a.chuong="+s_IDChuong;
				if(s_IDHoatdong!="")sql_dk+=" and a.hoatdong="+s_IDHoatdong;
				if(s_IDNhombc!="")sql_dk+=" and a.idbc="+s_IDNhombc;
				if(s_IDdoituong!="")sql_dk+=" and a.madt='"+s_IDdoituong+"'";
				if(s_muc!="")sql_dk+=" and a.mtmuc in ("+s_muc+")";
				if (s_IDkm!="") sql_dk+=" and a.khoanmuc = '"+s_IDkm+"'";		
				if (s_IDkm2!="") sql_dk+=" and a.khoanmuc2 = '"+s_IDkm2+"'";			
				if (s_IDkm3!="") sql_dk+=" and a.khoanmuc3 = '"+s_IDkm3+"'";			
				if (s_IDkm4!="") sql_dk+=" and a.khoanmuc4 = '"+s_IDkm4+"'";
				if(i<denthang)
					sql_dk+=") union ";
				else
					sql_dk+=")";
			}			
			try
			{
				ds_Data=a.get_data(sql);
				//				if(ds_Data==null||ds_Data.Tables[0].Rows.Count<=0)
				//					flag_dsnull=true;
				//				else				
				//				{					
				if(i_dkgroup!=-1)
				{
					ds_Data2=a.get_dsSodudauky(s_mm,s_mm1,s_yy,s_IDChuong,s_IDtk,s_IDlk,s_IDkm,s_IDHoatdong,s_IDNhombc,s_IDdoituong,s_muc,s_IDkm2,s_IDkm3,s_IDkm4,i_dkgroup);
					if(ds_Data2!=null)
					{
						ds_Data.Merge(ds_Data2);
						ds_Data.AcceptChanges();
					}
				}					
				ds_Data3=a.get_data(sql_dk);
				if(ds_Data3!=null)
					ds_Data.Merge(ds_Data3);
				ds_Data.AcceptChanges();
				
				//				}
				if ((ds_Data==null || ds_Data.Tables[0].Rows.Count<=0)) flag_dsnull=true;				
			}
			catch
			{
				flag_dsnull=true;
			}	
			//tinh luy ke nam	
			
			//try
			//{		
			if(flag_dsnull!=true)
			{
				for(int lk=tuthang;lk<=denthang;lk++)
				{
					System.Data.DataRow dr_LuyKe = ds_Data.Tables[0].NewRow();
				
					dr_LuyKe["ngayct"]="";
					dr_LuyKe["thang"]=lk.ToString().PadLeft(2,'0');
					dr_LuyKe["soctg"]="";
					dr_LuyKe["ngaygs"]="";
					dr_LuyKe["diengiai"]="";
					dr_LuyKe["tkno"]="";
					dr_LuyKe["tkco"]="";
					dr_LuyKe["tkdoiung"]="";
					dr_LuyKe["no"]= 0;
					dr_LuyKe["co"]= 0;
			
				
					int CT_Quy = ((lk-1)/3)*3+1;
					if(lk==tuthang)
					{
						dr_LuyKe["luykenam_co"]=a.get_FSluykenam_quy(s_yy,s_sotk,s_IDlk,2,1,tuthang,s_IDChuong,s_IDHoatdong,s_IDNhombc,s_IDdoituong,s_muc,s_IDkm,s_IDkm2,s_IDkm3,s_IDkm4);//b_CheckChuong,s_IDChuong,b_CheckHoatDong,s_IDHoatDong,s_IDNhombc,b_CheckNhombc);
						dr_LuyKe["luykenam_no"]=a.get_FSluykenam_quy(s_yy,s_sotk,s_IDlk,1,1,tuthang,s_IDChuong,s_IDHoatdong,s_IDNhombc,s_IDdoituong,s_muc,s_IDkm,s_IDkm2,s_IDkm3,s_IDkm4);//b_CheckChuong,s_IDChuong,b_CheckHoatDong,s_IDHoatDong,s_IDNhombc,b_CheckNhombc);

						dr_LuyKe["luykequy_co"]=a.get_FSluykenam_quy(s_yy,s_sotk,s_IDlk,2,CT_Quy,tuthang,s_IDChuong,s_IDHoatdong,s_IDNhombc,s_IDdoituong,s_muc,s_IDkm,s_IDkm2,s_IDkm3,s_IDkm4);//b_CheckChuong,s_IDChuong,b_CheckHoatDong,s_IDHoatDong,s_IDNhombc,b_CheckNhombc);
						dr_LuyKe["luykequy_no"]=a.get_FSluykenam_quy(s_yy,s_sotk,s_IDlk,1,CT_Quy,tuthang,s_IDChuong,s_IDHoatdong,s_IDNhombc,s_IDdoituong,s_muc,s_IDkm,s_IDkm2,s_IDkm3,s_IDkm4);//b_CheckChuong,s_IDChuong,b_CheckHoatDong,s_IDHoatDong,s_IDNhombc,b_CheckNhombc);
					}
					else
					{	
						dr_LuyKe["luykenam_co"]=a.get_FSluykenam_quy(s_yy,s_sotk,s_IDlk,2,1,lk,s_IDChuong,s_IDHoatdong,s_IDNhombc,s_IDdoituong,s_muc,s_IDkm,s_IDkm2,s_IDkm3,s_IDkm4);//b_CheckChuong,s_IDChuong,b_CheckHoatDong,s_IDHoatDong,s_IDNhombc,b_CheckNhombc);
						dr_LuyKe["luykenam_no"]=a.get_FSluykenam_quy(s_yy,s_sotk,s_IDlk,1,1,lk,s_IDChuong,s_IDHoatdong,s_IDNhombc,s_IDdoituong,s_muc,s_IDkm,s_IDkm2,s_IDkm3,s_IDkm4);//b_CheckChuong,s_IDChuong,b_CheckHoatDong,s_IDHoatdong,s_IDNhombc,b_CheckNhombc);
						dr_LuyKe["luykequy_co"]=a.get_FSluykenam_quy(s_yy,s_sotk,s_IDlk,2,CT_Quy,lk,s_IDChuong,s_IDHoatdong,s_IDNhombc,s_IDdoituong,s_muc,s_IDkm,s_IDkm2,s_IDkm3,s_IDkm4);//b_CheckChuong,s_IDChuong,b_CheckHoatDong,s_IDHoatDong,s_IDNhombc,b_CheckNhombc);
						dr_LuyKe["luykequy_no"]=a.get_FSluykenam_quy(s_yy,s_sotk,s_IDlk,1,CT_Quy,lk,s_IDChuong,s_IDHoatdong,s_IDNhombc,s_IDdoituong,s_muc,s_IDkm,s_IDkm2,s_IDkm3,s_IDkm4);//b_CheckChuong,s_IDChuong,b_CheckHoatDong,s_IDHoatDong,s_IDNhombc,b_CheckNhombc);
					}
					ds_Data.Tables[0].Rows.Add(dr_LuyKe);
					ds_Data.AcceptChanges();			
				}
			}
			//}
			//catch{};
			try
			{
				if ((ds_Data==null || ds_Data.Tables[0].Rows.Count<=0)) flag_dsnull=true;
//				ds_Data.WriteXml("..\\xml\\KT_SoCai_S3b.xml",XmlWriteMode.WriteSchema);
				if(s_Tenform=="SOCAI_S3b")
					ds_Data=f_Sort(ds_Data);
				ds_Data.AcceptChanges();
				if ((ds_Data==null || ds_Data.Tables[0].Rows.Count<=0)) flag_dsnull=true;
//				ds_Data.WriteXml("..\\xml\\KT_SoCai_S3b.xml",XmlWriteMode.WriteSchema);
			}
			catch{};
			if (flag_dsnull) return null;
			else return ds_Data;
		}


        public System.Data.DataSet SoTheoDoiHangMucKinhPhi(LibKetoan.AccessData a, string s_IDtk, string s_sotk, string s_IDlk, string s_Tungay, string s_Denngay, string s_mm, string s_mm1, string s_yy, string s_yyyy, bool b_Checkngay, string s_IDChuong, string s_IDHoatdong, string s_IDNhombc, string s_IDkm, string s_IDkm2, string s_IDkm3, string s_IDkm4, string s_muc, string s_IDdoituong, int i_dkgroup, string s_Tenform)
        {
            string s_DKgroup = "";
            if (i_dkgroup != -1) s_DKgroup = ", " + i_dkgroup + " as nhom";
            else s_DKgroup = ", -1 as nhom ";

            string s_DKSelectgroup = "", s_DKGroupbygroup = "", s_DKfrom = "";
            switch (i_dkgroup)
            {
                case 0:
                    s_DKSelectgroup = " ch.ten as chuong,ch.id as idchuong,";
                    s_DKSelectgroup += " 0 as iddoituong, 0 as idnhombc,0 as idhoatdong, 0 as idmuc, 0 as idkm, 0 as idkm2, 0 as idkm3, 0 as idkm4,";
                    s_DKSelectgroup += " '' as doituong, '' as nhombc,'' as hoatdong, '' as muc, '' as km, '' as km2, '' as km3, '' as km4,";
                    s_DKGroupbygroup = " ch.ten,ch.id,";
                    s_DKGroupbygroup += " '', '', '', '', '', '', '','',";
                    s_DKGroupbygroup += " '', '', '', '', '', '', '','',";
                    s_DKfrom = " left join " + a.user + ".a_dmchuong ch on ct.chuong=ch.id";
                    break;
                case 1:
                    s_DKSelectgroup = " dt.tendt as doituong,dt.id as iddoituong,";
                    s_DKSelectgroup += " 0 as idchuong, 0 as idnhombc,0 as idhoatdong, 0 as idmuc, 0 as idkm, 0 as idkm2, 0 as idkm3, 0 as idkm4,";
                    s_DKSelectgroup += " '' as chuong, '' as nhombc,'' as hoatdong, '' as muc, '' as km, '' as km2, '' as km3, '' as km4,";
                    s_DKGroupbygroup = " dt.tendt,dt.id,";
                    s_DKGroupbygroup += " '', '', '', '', '', '', '','',";
                    s_DKGroupbygroup += " '', '', '', '', '', '', '','',";
                    s_DKfrom = " left join " + a.user + ".a_dmdt dt on ct.madt=dt.id";
                    break;
                case 2:
                    s_DKSelectgroup = " hd.ten as hoatdong,hd.id as idhoatdong,";
                    s_DKSelectgroup += " 0 as idchuong,0 as iddoituong, 0 as idnhombc,0 as idmuc, 0 as idkm, 0 as idkm2, 0 as idkm3, 0 as idkm4,";
                    s_DKSelectgroup += " '' as chuong,'' as doituong, '' as nhombc,'' as muc, '' as km, '' as km2, '' as km3, '' as km4,";
                    s_DKGroupbygroup = " hd.ten,hd.id,";
                    s_DKfrom = " left join " + a.user + ".a_hoatdong hd on ct.hoatdong=hd.id";
                    s_DKGroupbygroup += " '', '', '', '', '', '', '','',";
                    s_DKGroupbygroup += " '', '', '', '', '', '', '','',";
                    break;
                case 3:
                    s_DKSelectgroup = " case when(chno.ttk <>' ') then chno.ttk else chco.ttk end as muc,";
                    s_DKSelectgroup += " case when(chno.ttk <>' ') then chno.id else chco.id end as idmuc,";
                    s_DKSelectgroup += " 0 as idchuong,0 as iddoituong, 0 as idnhombc,0 as idhoatdong, 0 as idkm, 0 as idkm2, 0 as idkm3, 0 as idkm4,";
                    s_DKSelectgroup += " '' as chuong,'' as doituong, '' as nhombc,'' as hoatdong, '' as km, '' as km2, '' as km3, '' as km4,";
                    s_DKGroupbygroup = " case when(chno.ttk <>' ') then chno.id else chco.id end,";
                    s_DKGroupbygroup += " case when(chno.ttk <>' ') then chno.ttk else chco.ttk end,";
                    s_DKGroupbygroup += " '', '', '', '', '', '', '','',";
                    s_DKGroupbygroup += " '', '', '', '', '', '', '','',";
                    s_DKfrom = " left join " + a.user + ".a_dmch chco on ctct.mtmco=chco.id";
                    s_DKfrom += " left join " + a.user + ".a_dmch chno on ctct.mtmno=chno.id";
                    break;
                case 4:
                    s_DKSelectgroup = " bc.ten as nhombc,bc.id as idnhombc,";
                    s_DKSelectgroup += " 0 as idchuong, 0 as iddoituong,0 as idhoatdong, 0 as idmuc, 0 as idkm, 0 as idkm2, 0 as idkm3, 0 as idkm4,";
                    s_DKSelectgroup += " '' as chuong, '' as doituong,'' as hoatdong, '' as muc, '' as km, '' as km2, '' as km3, '' as km4,";
                    s_DKGroupbygroup = " bc.ten,bc.id,";
                    s_DKGroupbygroup += " '', '', '', '', '', '', '','',";
                    s_DKGroupbygroup += " '', '', '', '', '', '', '','',";
                    s_DKfrom = "left join " + a.user + ".a_dmnhombc bc on ct.idbc=bc.id";
                    break;
                case 5:
                    s_DKSelectgroup = " case when (kmno.ten <>' ') then kmno.ten else kmco.ten end as km,";
                    s_DKSelectgroup += " case when (kmno.ten <>' ') then kmno.id else kmco.id end as idkm,";
                    s_DKSelectgroup += " 0 as idchuong, 0 as idnhombc,0 as idhoatdong, 0 as idmuc,0 as iddoituong, 0 as idkm2, 0 as idkm3, 0 as idkm4,";
                    s_DKSelectgroup += " '' as chuong, '' as nhombc,'' as hoatdong, '' as muc, '' as doituong, '' as km2, '' as km3, '' as km4,";
                    s_DKGroupbygroup = " case when(kmno.ten <>' ') then kmno.ten else kmco.ten end,";
                    s_DKGroupbygroup += " case when(kmno.ten <>' ') then kmno.id else kmco.id end,";
                    s_DKGroupbygroup += " '', '', '', '', '', '', '','',";
                    s_DKGroupbygroup += " '', '', '', '', '', '', '','',";
                    s_DKfrom = " left join " + a.user + ".a_dmkhoanmuc kmno on ctct.kmno=kmno.id";
                    s_DKfrom += " left join " + a.user + ".a_dmkhoanmuc kmco on ctct.kmco=kmco.id";
                    break;
                case 6:
                    s_DKSelectgroup = " case when (kmno2.ten <>' ') then kmno2.ten else kmco2.ten end as km2,";
                    s_DKSelectgroup += " case when (kmno2.ten <>' ') then kmno2.id else kmco2.id end as idkm2,";
                    s_DKSelectgroup += " 0 as idchuong, 0 as idnhombc,0 as idhoatdong, 0 as idmuc, 0 as idkm, 0 as iddoituong, 0 as idkm3, 0 as idkm4,";
                    s_DKSelectgroup += " '' as chuong, '' as nhombc,'' as hoatdong, '' as muc, '' as km, '' as doituong, '' as km3, '' as km4,";
                    s_DKGroupbygroup = " case when(kmno2.ten<>' ') then kmno2.ten else kmco2.ten end,";
                    s_DKGroupbygroup += " case when(kmno2.ten<>' ') then kmno2.id else kmco2.id end,";
                    s_DKGroupbygroup += " '', '', '', '', '', '', '','',";
                    s_DKGroupbygroup += " '', '', '', '', '', '', '','',";
                    s_DKfrom = " left join " + a.user + ".a_dmkhoanmuc kmno2 on ctct.kmno2=kmno2.id";
                    s_DKfrom += " left join " + a.user + ".a_dmkhoanmuc kmco2 on ctct.kmco2=kmco2.id";
                    break;
                case 7:
                    s_DKSelectgroup = " case when (kmno3.ten<>' ') then kmno3.ten else kmco3.ten end as km3,";
                    s_DKSelectgroup += " case when (kmno3.ten<>' ') then kmno3.id else kmco3.id end as idkm3,";
                    s_DKSelectgroup += " 0 as idchuong, 0 as idnhombc,0 as idhoatdong, 0 as idmuc, 0 as idkm, 0 as idkm2, 0 as iddoituong, 0 as idkm4,";
                    s_DKSelectgroup += " '' as chuong, '' as nhombc,'' as hoatdong, '' as muc, '' as km, '' as km2, '' as doituong, '' as km4,";
                    s_DKGroupbygroup = " case when(kmno3.ten<>' ' ) then kmno3.ten else kmco3.ten end,";
                    s_DKGroupbygroup += " case when(kmno3.ten<>' ' ) then kmno3.id else kmco3.id end,";
                    s_DKGroupbygroup += " '', '', '', '', '', '', '','',";
                    s_DKGroupbygroup += " '', '', '', '', '', '', '','',";
                    s_DKfrom = " left join " + a.user + ".a_dmkhoanmuc kmno3 on ctct.kmno3=kmno3.id";
                    s_DKfrom += " left join " + a.user + ".a_dmkhoanmuc kmco3 on ctct.kmco3=kmco3.id";
                    break;
                case 8:
                    s_DKSelectgroup = " case when (kmno4.ten<>' ') then kmno4.ten else kmco4.ten end as km4,";
                    s_DKSelectgroup += " case when (kmno4.ten<>' ') then kmno4.id else kmco4.id end as idkm4,";
                    s_DKSelectgroup += " 0 as idchuong, 0 as idnhombc,0 as idhoatdong, 0 as idmuc, 0 as idkm, 0 as idkm2, 0 as idkm3, 0 as iddoituong,";
                    s_DKSelectgroup += " '' as chuong, '' as nhombc,'' as hoatdong, '' as muc, '' as km, '' as km2, '' as km3, '' as doituong,";
                    s_DKfrom = " left join " + a.user + ".a_dmkhoanmuc kmno4 on ctct.kmno4=kmno4.id";
                    s_DKfrom += " left join " + a.user + ".a_dmkhoanmuc kmco4 on ctct.kmco4=kmco4.id"; s_DKGroupbygroup = " case when(kmno4.ten<>' ') then kmno4.ten else kmco4.ten end,";
                    s_DKGroupbygroup += " case when(kmno4.ten<>' ') then kmno4.id else kmco4.id end,";
                    s_DKGroupbygroup += " '', '', '', '', '', '', '','',";
                    s_DKGroupbygroup += " '', '', '', '', '', '', '','',";
                    break;
                default:
                    s_DKSelectgroup += " 0 as idchuong, 0 as idnhombc,0 as idhoatdong, 0 as idmuc, 0 as idkm, 0 as idkm2, 0 as idkm3, 0 as idkm4,0 as iddoituong,";
                    s_DKSelectgroup += " '' as chuong, '' as nhombc,'' as hoatdong, '' as muc, '' as km, '' as km2, '' as km3, '' as km4,'' as doituong,";
                    s_DKGroupbygroup += " '', '', '', '', '', '', '','',";
                    s_DKGroupbygroup += " '', '', '', '', '', '', '','',";
                    break;
            }


            sql = "select distinct ct.id, to_char(ct.ngayg,'dd/mm/yyyy') as ngayct,ct.thanggs as thang,";
            sql += " ct.soctg as soctg, to_char(ct.ngaygs,'dd/mm/yyyy') as ngaygs,dmtkno.stk as tkno, dmtkco.stk as tkco,";
            if (s_Tenform == "SOHANGMUCKINHPHI") sql += " ct.noidung as diengiai,";
            else sql += " nvl(ctct.noidung,ct.noidung) diengiai,";
            sql += " (case when ctct.tknoa in(" + s_IDtk + ") then dmtkco.stk else (case when";
            sql += " ctct.tkcoa in(" + s_IDtk + ") then dmtkno.stk else '' end) end) tkdoiung,";
            sql += " sum(case when ctct.tknoa in(" + s_IDtk + ") then ctct.stien else 0 end) no,";
            sql += " sum(case when ctct.tkcoa in(" + s_IDtk + ") then ctct.stien else 0 end) co,";
            sql += " " + s_DKSelectgroup + "";
            sql += " 0 luykenam_co, 0 luykenam_no, 0 luykequy_co, 0 luykequy_no,";
            sql += " 0 sodu_no,0 sodu_co";
            sql += " " + s_DKgroup + "";
            sql += " from " + a.user + ".a_ct" + s_yy + " ct inner join " + a.user + ".a_ctct" + s_yy + " ctct on ct.id=ctct.idct";
            sql += " left join " + a.user + ".a_dmlk lk on ctct.lk=lk.id";
            sql += " " + s_DKfrom + "";
            sql += " left join " + a.user + ".a_dmtk dmtkno on ctct.tknoa=dmtkno.id";
            sql += " left join " + a.user + ".a_dmtk dmtkco on ctct.tkcoa=dmtkco.id";
            sql += " where ctct.tonghop=1";
            if (b_Checkngay) sql += " and to_date(to_char(ct.ngayg,'dd/mm/yyyy'),'dd/mm/yyyy') between to_date('" + s_Tungay + "','dd/mm/yyyy') and to_date('" + s_Denngay + "','dd/mm/yyyy')";
            else sql += " and ct.thanggs between '" + s_mm + "' and '" + s_mm1 + "'";
            if (s_IDlk != "") sql += " and lk.id='" + s_IDlk + "'";
            sql += " and (ctct.tknoa in(" + s_IDtk + ") or ctct.tkcoa in(" + s_IDtk + "))";
            if (s_IDChuong != "") sql += " and ct.chuong=" + s_IDChuong;
            if (s_IDHoatdong != "") sql += " and ct.hoatdong=" + s_IDHoatdong;
            if (s_IDNhombc != "") sql += " and ct.idbc=" + s_IDNhombc;
            if (s_IDkm != "") sql += " and (ctct.kmno like '" + s_IDkm + "' or ctct.kmco like '" + s_IDkm + "')";
            if (s_IDkm2 != "") sql += " and (ctct.kmno2 like '" + s_IDkm2 + "' or ctct.kmco2 like '" + s_IDkm2 + "'";
            if (s_IDkm3 != "") sql += " and (ctct.kmno3 like '" + s_IDkm3 + "' or ctct.kmco3 like '" + s_IDkm3 + "'";
            if (s_IDkm4 != "") sql += " and (ctct.kmno4 like '" + s_IDkm4 + "' or ctct.kmco4 like '" + s_IDkm4 + "'";
            if (s_IDdoituong != "") sql += " and ct.madt=" + s_IDdoituong;
            if (s_muc != "") sql += " and (chno.id in(" + s_muc + ") or chco.id in (" + s_muc + "))";
            sql += " group by ";
            sql += " " + s_DKGroupbygroup + "";
            sql += " ct.id,ct.ngayg,ct.thanggs,";
            sql += " ct.soctg, ct.ngaygs,dmtkno.stk, dmtkco.stk,";
            if (s_Tenform == "SOHANGMUCKINHPHI") sql += " ct.noidung,";
            else sql += " nvl(ctct.noidung,ct.noidung),";
            sql += " (case when ctct.tknoa in(" + s_IDtk + ") then dmtkco.stk else (case when";
            sql += " ctct.tkcoa in(" + s_IDtk + ") then dmtkno.stk else '' end) end)";
            sql += " order by ct.id,ct.soctg";

            //tinh so du dau ky
            int tuthang = Convert.ToInt32(s_mm);
            int denthang = Convert.ToInt32(s_mm1);

            string sql_dk = "";
            for (int i = tuthang; i <= denthang; i++)
            {
                sql_dk += " (select sum(sdco" + i.ToString().PadLeft(2, '0') + ") as sodudk_co,";
                sql_dk += " sum(sdno" + i.ToString().PadLeft(2, '0') + ") as sodudk_no,";
                sql_dk += "'" + i.ToString().PadLeft(2, '0') + "' as thang,0 as no,0 as co";
                sql_dk += " from " + a.user + ".a_sd" + s_yy + " a";
                sql_dk += " where a.stka in (" + s_IDtk + ")";
                if (s_IDlk != "") sql_dk += " and a.lk=" + s_IDlk;
                if (s_IDChuong != "") sql_dk += " and a.chuong=" + s_IDChuong;
                if (s_IDHoatdong != "") sql_dk += " and a.hoatdong=" + s_IDHoatdong;
                if (s_IDNhombc != "") sql_dk += " and a.idbc=" + s_IDNhombc;
                if (s_IDdoituong != "") sql_dk += " and a.madt='" + s_IDdoituong + "'";
                if (s_muc != "") sql_dk += " and a.mtmuc in (" + s_muc + ")";
                if (s_IDkm != "") sql_dk += " and a.khoanmuc = '" + s_IDkm + "'";
                if (s_IDkm2 != "") sql_dk += " and a.khoanmuc2 = '" + s_IDkm2 + "'";
                if (s_IDkm3 != "") sql_dk += " and a.khoanmuc3 = '" + s_IDkm3 + "'";
                if (s_IDkm4 != "") sql_dk += " and a.khoanmuc4 = '" + s_IDkm4 + "'";
                if (i < denthang)
                    sql_dk += ") union ";
                else
                    sql_dk += ")";
            }
            try
            {
                ds_Data = a.get_data(sql);
                //				if(ds_Data==null||ds_Data.Tables[0].Rows.Count<=0)
                //					flag_dsnull=true;
                //				else				
                //				{					
                if (i_dkgroup != -1)
                {
                    ds_Data2 = a.get_dsSodudauky(s_mm, s_mm1, s_yy, s_IDChuong, s_IDtk, s_IDlk, s_IDkm, s_IDHoatdong, s_IDNhombc, s_IDdoituong, s_muc, s_IDkm2, s_IDkm3, s_IDkm4, i_dkgroup);
                    if (ds_Data2 != null)
                    {
                        ds_Data.Merge(ds_Data2);
                        ds_Data.AcceptChanges();
                    }
                }
                ds_Data3 = a.get_data(sql_dk);
                if (ds_Data3 != null)
                    ds_Data.Merge(ds_Data3);
                ds_Data.AcceptChanges();

                //				}
                if ((ds_Data == null || ds_Data.Tables[0].Rows.Count <= 0)) flag_dsnull = true;
            }
            catch
            {
                flag_dsnull = true;
            }
            //tinh luy ke nam	

            //try
            //{		
            if (flag_dsnull != true)
            {
                for (int lk = tuthang; lk <= denthang; lk++)
                {
                    System.Data.DataRow dr_LuyKe = ds_Data.Tables[0].NewRow();

                    dr_LuyKe["ngayct"] = "";
                    dr_LuyKe["thang"] = lk.ToString().PadLeft(2, '0');
                    dr_LuyKe["soctg"] = "";
                    dr_LuyKe["ngaygs"] = "";
                    dr_LuyKe["diengiai"] = "";
                    dr_LuyKe["tkno"] = "";
                    dr_LuyKe["tkco"] = "";
                    dr_LuyKe["tkdoiung"] = "";
                    dr_LuyKe["no"] = 0;
                    dr_LuyKe["co"] = 0;


                    int CT_Quy = ((lk - 1) / 3) * 3 + 1;
                    if (lk == tuthang)
                    {
                        dr_LuyKe["luykenam_co"] = a.get_FSluykenam_quy(s_yy, s_sotk, s_IDlk, 2, 1, tuthang, s_IDChuong, s_IDHoatdong, s_IDNhombc, s_IDdoituong, s_muc, s_IDkm, s_IDkm2, s_IDkm3, s_IDkm4);//b_CheckChuong,s_IDChuong,b_CheckHoatDong,s_IDHoatDong,s_IDNhombc,b_CheckNhombc);
                        dr_LuyKe["luykenam_no"] = a.get_FSluykenam_quy(s_yy, s_sotk, s_IDlk, 1, 1, tuthang, s_IDChuong, s_IDHoatdong, s_IDNhombc, s_IDdoituong, s_muc, s_IDkm, s_IDkm2, s_IDkm3, s_IDkm4);//b_CheckChuong,s_IDChuong,b_CheckHoatDong,s_IDHoatDong,s_IDNhombc,b_CheckNhombc);

                        dr_LuyKe["luykequy_co"] = a.get_FSluykenam_quy(s_yy, s_sotk, s_IDlk, 2, CT_Quy, tuthang, s_IDChuong, s_IDHoatdong, s_IDNhombc, s_IDdoituong, s_muc, s_IDkm, s_IDkm2, s_IDkm3, s_IDkm4);//b_CheckChuong,s_IDChuong,b_CheckHoatDong,s_IDHoatDong,s_IDNhombc,b_CheckNhombc);
                        dr_LuyKe["luykequy_no"] = a.get_FSluykenam_quy(s_yy, s_sotk, s_IDlk, 1, CT_Quy, tuthang, s_IDChuong, s_IDHoatdong, s_IDNhombc, s_IDdoituong, s_muc, s_IDkm, s_IDkm2, s_IDkm3, s_IDkm4);//b_CheckChuong,s_IDChuong,b_CheckHoatDong,s_IDHoatDong,s_IDNhombc,b_CheckNhombc);
                    }
                    else
                    {
                        dr_LuyKe["luykenam_co"] = a.get_FSluykenam_quy(s_yy, s_sotk, s_IDlk, 2, 1, lk, s_IDChuong, s_IDHoatdong, s_IDNhombc, s_IDdoituong, s_muc, s_IDkm, s_IDkm2, s_IDkm3, s_IDkm4);//b_CheckChuong,s_IDChuong,b_CheckHoatDong,s_IDHoatDong,s_IDNhombc,b_CheckNhombc);
                        dr_LuyKe["luykenam_no"] = a.get_FSluykenam_quy(s_yy, s_sotk, s_IDlk, 1, 1, lk, s_IDChuong, s_IDHoatdong, s_IDNhombc, s_IDdoituong, s_muc, s_IDkm, s_IDkm2, s_IDkm3, s_IDkm4);//b_CheckChuong,s_IDChuong,b_CheckHoatDong,s_IDHoatdong,s_IDNhombc,b_CheckNhombc);
                        dr_LuyKe["luykequy_co"] = a.get_FSluykenam_quy(s_yy, s_sotk, s_IDlk, 2, CT_Quy, lk, s_IDChuong, s_IDHoatdong, s_IDNhombc, s_IDdoituong, s_muc, s_IDkm, s_IDkm2, s_IDkm3, s_IDkm4);//b_CheckChuong,s_IDChuong,b_CheckHoatDong,s_IDHoatDong,s_IDNhombc,b_CheckNhombc);
                        dr_LuyKe["luykequy_no"] = a.get_FSluykenam_quy(s_yy, s_sotk, s_IDlk, 1, CT_Quy, lk, s_IDChuong, s_IDHoatdong, s_IDNhombc, s_IDdoituong, s_muc, s_IDkm, s_IDkm2, s_IDkm3, s_IDkm4);//b_CheckChuong,s_IDChuong,b_CheckHoatDong,s_IDHoatDong,s_IDNhombc,b_CheckNhombc);
                    }
                    ds_Data.Tables[0].Rows.Add(dr_LuyKe);
                    ds_Data.AcceptChanges();
                }
            }
            //}
            //catch{};
            try
            {
                if ((ds_Data == null || ds_Data.Tables[0].Rows.Count <= 0)) flag_dsnull = true;
                //				ds_Data.WriteXml("..\\xml\\KT_SoCai_S3b.xml",XmlWriteMode.WriteSchema);
                if (s_Tenform == "SOHANGMUCKINHPHI")
                    ds_Data = f_Sort(ds_Data);
                ds_Data.AcceptChanges();
                if ((ds_Data == null || ds_Data.Tables[0].Rows.Count <= 0)) flag_dsnull = true;
                //				ds_Data.WriteXml("..\\xml\\KT_SoCai_S3b.xml",XmlWriteMode.WriteSchema);
            }
            catch { };
            if (flag_dsnull) return null;
            else return ds_Data;
        }
		

        private DataSet f_Sort(DataSet ads)
		{
			DataSet adsxml=ads.Clone();
			string strID="",strTkdoiung="";
			decimal d_No=0,d_Co=0;
			DataRow row;

			foreach(DataRow r in ads.Tables[0].Select("","id"))
			{
				strTkdoiung="";
				d_No=0;d_Co=0;
				if(r["id"].ToString()=="")
				{
					adsxml.Tables[0].Rows.Add(r.ItemArray);
				}
				else
				{
					if(strID!=r["id"].ToString())
					{
						strID=r["id"].ToString();
						foreach(DataRow _r in ads.Tables[0].Select("id='"+strID+"'"))
						{								
							strTkdoiung+=_r["tkdoiung"].ToString()+",";
							if(_r["no"].ToString()!="")d_No+=decimal.Parse(_r["no"].ToString());
							if(_r["co"].ToString()!="")d_Co+=decimal.Parse(_r["co"].ToString());
						}
						if(strTkdoiung!="")strTkdoiung=strTkdoiung.Substring(0,strTkdoiung.Length-1);						

						#region add row
						row=adsxml.Tables[0].NewRow();
						row["NGAYCT"]=r["NGAYCT"].ToString();
						row["THANG"]=r["THANG"].ToString();
						row["SOCTG"]=r["SOCTG"].ToString();
						row["NGAYGS"]=r["NGAYGS"].ToString();
						row["TKNO"]=r["TKNO"].ToString();
						row["TKCO"]=r["TKCO"].ToString();
						row["DIENGIAI"]=r["DIENGIAI"].ToString();
						row["TKDOIUNG"]=strTkdoiung;
						row["NO"]=d_No;
						row["CO"]=d_Co;	
						if(r["IDCHUONG"].ToString()!="")row["IDCHUONG"]=r["IDCHUONG"].ToString();
						else row["IDCHUONG"]=0;
						if(r["IDDOITUONG"].ToString()!="")row["IDDOITUONG"]=r["IDDOITUONG"].ToString();
						else row["IDDOITUONG"]=0;
						if(r["IDHOATDONG"].ToString()!="")row["IDHOATDONG"]=r["IDHOATDONG"].ToString();
						else row["IDHOATDONG"]=0;
						if(r["IDMUC"].ToString()!="")row["IDMUC"]=r["IDMUC"].ToString();
						else row["IDMUC"]=0;
						if(r["IDNHOMBC"].ToString()!="")row["IDNHOMBC"]=r["IDNHOMBC"].ToString();
						else row["IDNHOMBC"]=0;
						if(r["IDKM"].ToString()!="")row["IDKM"]=r["IDKM"].ToString();
						else row["IDKM"]=0;
						if(r["IDKM2"].ToString()!="")row["IDKM2"]=r["IDKM2"].ToString();
						else row["IDKM2"]=0;
						if(r["IDKM3"].ToString()!="")row["IDKM3"]=r["IDKM3"].ToString();
						else row["IDKM3"]=0;
						if(r["IDKM4"].ToString()!="")row["IDKM4"]=r["IDKM4"].ToString();
						else row["IDKM4"]=0;

						row["CHUONG"]=r["CHUONG"].ToString();     
						row["NHOMBC"]=r["NHOMBC"].ToString();
						row["HOATDONG"]=r["HOATDONG"].ToString();
						row["MUC"]=r["MUC"].ToString();
						row["KM"]=r["KM"].ToString();
						row["KM2"]=r["KM2"].ToString();
						row["KM3"]=r["KM3"].ToString();
						row["KM4"]=r["KM4"].ToString();
						row["DOITUONG"]=r["DOITUONG"].ToString();
						if(r["LUYKENAM_CO"].ToString()!="")	row["LUYKENAM_CO"]=r["LUYKENAM_CO"].ToString();
						else row["LUYKENAM_CO"]=0;
						if(r["LUYKENAM_NO"].ToString()!="")	row["LUYKENAM_NO"]=r["LUYKENAM_NO"].ToString();
						else row["LUYKENAM_NO"]=0;
						if(r["LUYKEQUY_CO"].ToString()!="")row["LUYKEQUY_CO"]=r["LUYKEQUY_CO"].ToString();
						else row["LUYKEQUY_CO"]=0;
						if(r["LUYKEQUY_NO"].ToString()!="") row["LUYKEQUY_NO"]=r["LUYKEQUY_NO"].ToString();
						else row["LUYKEQUY_NO"]=0;
						if(r["SODU_NO"].ToString()!="") row["SODU_NO"]=r["SODU_NO"].ToString();
						else row["SODU_NO"]=0;
						if(r["SODU_NO"].ToString()!="") row["SODU_NO"]=r["SODU_NO"].ToString();
						else row["SODU_NO"]=0;
						if(r["SODU_CO"].ToString()!="")row["SODU_CO"]=r["SODU_CO"].ToString();
						else row["SODU_CO"]=0;
						if(r["NHOM"].ToString()!="")row["NHOM"]=r["NHOM"].ToString();
						if(	r["SODUDK_CO"].ToString()!="")row["SODUDK_CO"]=r["SODUDK_CO"].ToString();
						else row["SODUDK_CO"]=0;
						if(r["SODUDK_NO"].ToString()!="")row["SODUDK_NO"]=r["SODUDK_NO"].ToString();
						else row["SODUDK_NO"]=0;
						
						adsxml.Tables[0].Rows.Add(row);
						#endregion add row
								
								

					}
				}

			}
			return adsxml;
	
		}
		public System.Data.DataSet SoCTChiHoatDong(LibKetoan.AccessData a, string s_sotk, string s_IDlk, string s_Tungay, string s_Denngay, string s_mm, string s_mm1, string s_yy, string s_yyyy, bool b_Checkngay, string s_IDChuong, string s_IDHoatdong, string s_IDMuc,string s_IDNhombc)
		{	
			sql=" select ttb2.tentmtm,ttb1.* from(";
			sql+=" select distinct tb2.tentm,tb1.* from(";
			sql+=" select distinct t2.tenmuc,t1.* from (";			
			sql+="select distinct to_char(a.ngayg, 'dd/mm/yyyy') as ngayg, a.soctg as soctg,a.ctgs as ctgs, ";
			sql+=" to_char(a.ngaygs, 'dd/mm/yyyy') as ngaygs,nhmuc as nhom,";
			sql+=" b.noidung as noidung, c.stk as sotk, g.ttk as ttk,";	
			sql+=" substr(trim(mtm),6,length(trim(mtm))) as tmtm, substr(trim(mtm),0,4) as muc,";
			sql+=" substr(trim(mtm),6,4) as tm,";		
			sql+=" sum(case when c.stk like '"+s_sotk+"%' then b.stien else 0 end) as no,";
			sql+=" sum(case when d.stk like '"+s_sotk+"%' then b.stien else 0 end) as co,";
			sql+=" 0 as sodu_no,0 as sodu_co";
			sql+=" from "+a.user+".a_ct"+s_yy+" a inner join "+a.user+".a_ctct"+s_yy+" b on a.id=b.idct";
			sql+=" inner join "+a.user+".a_dmtk c on b.tknoa = c.id";			
			sql+=" inner join "+a.user+".a_dmtk d on b.tkcoa = d.id";
			if(s_IDMuc!="")sql+=" inner join "+a.user+".a_dmch g on (g.id=b.mtmno or g.id=mtmco)";
			else sql+=" inner join "+a.user+".a_dmch g on (g.id=b.mtmno or g.id=mtmco)";
			sql+=" where (c.stk like '" + s_sotk + "%' or d.stk like '" + s_sotk + "%') ";
			sql+=" and b.tonghop=1 and a.ctgs is not null ";			
			if (b_Checkngay) sql+=" and to_date(to_char(a.ngayg,'dd/mm/yyyy'),'dd/mm/yyyy') between to_date('"+s_Tungay+"','dd/mm/yyyy') and to_date('"+s_Denngay+"','dd/mm/yyyy')";
			else sql+=" and a.thanggs between '"+s_mm+"' and '"+s_mm1+"'";			
			if (s_IDlk!="") sql+=" and b.lk="+s_IDlk;
			if(s_IDChuong!="")sql+=" and a.chuong="+s_IDChuong;
			if(s_IDHoatdong!="")sql+=" and a.hoatdong="+s_IDHoatdong;
			if(s_IDMuc!="") sql+= " and g.mtm like'"+s_IDMuc+"%'";
			if(s_IDNhombc!="")sql+=" and a.idbc="+s_IDNhombc;
			sql+=" group by to_char(a.ngayg, 'dd/mm/yyyy'), a.soctg,a.ctgs, to_char(a.ngaygs, 'dd/mm/yyyy'),";
			sql+=" nhmuc, b.noidung,c.stk,g.ttk,substr(trim(mtm),6,length(trim(mtm))), substr(trim(mtm),0,4),";
			sql+=" substr(trim(mtm),6,4)"; 
			sql+=" ) t1 left join (select ch.mtm as muc,ch.ttk as tenmuc from a_dmch ch where cd=3) t2 on t1.muc=t2.muc";
			sql+=" ) tb1 left join (select substr(trim(ch.mtm),6,4) as tm,ch.ttk as tentm from a_dmch ch where cd=2) tb2 on tb1.tm=tb2.tm";
			sql+=" ) ttb1 left join (select substr(trim(ch.mtm),6,length(trim(mtm))) as tmtm,ch.ttk as tentmtm from a_dmch ch where cd=1) ttb2 on ttb1.tmtm=ttb2.tmtm";
			//tinh so du dau ky
			int tuthang = Convert.ToInt32(s_mm);
			int denthang = Convert.ToInt32(s_mm1);
			string sql_dk = "";
			sql_dk=a.get_SdDauKy_muc(s_yy,s_mm,s_sotk,s_IDMuc,s_IDlk,s_IDChuong,s_IDHoatdong,s_IDNhombc);//b_CheckChuong,s_IDChuong,b_CheckHoatDong,s_IDHoatDong,s_IDNhombc,b_CheckNhombc);	
			ds_Data2=a.get_data(sql_dk);			
			try
			{
				ds_Data=a.get_data(sql);	
				if(ds_Data2!=null)				
					ds_Data.Merge(ds_Data2);
				ds_Data.AcceptChanges();				
				if ((ds_Data==null || ds_Data.Tables[0].Rows.Count<=0)) flag_dsnull=true;	
				ds_Data.WriteXml("..\\xml\\KT_SoChiTietChiHoatDong.xml",XmlWriteMode.WriteSchema);
				
			}
			catch
			{
				flag_dsnull=true;
			}			
			if (flag_dsnull) return null;
			else return ds_Data;
		}

		public System.Data.DataSet SoCTChiDuAn(LibKetoan.AccessData a, string s_IDlk,string s_sotk,string s_ttk,string s_IDMuc,string s_yy, bool b_Checkngay, string s_mm, string s_mm1,string s_Tungay,string s_Denngay,string s_IDChuong, string s_IDHoatdong, string s_IDNhombc)
		{	
			sql=" select distinct ttb2.tentmtm,ttb1.* from(";
			sql+=" select distinct tb2.tentm,tb1.* from(";
			sql+=" select distinct t2.tenmuc,t1.* from (";	
			sql+= "select to_char(a.ngayg,'dd/mm/yyyy') as ngayg,";
			sql+=" a.soctg as soctg,to_char(a.ngaygs,'dd/mm/yyyy') as ngaygs,";
			sql+=" b.noidung as noidung,nhmuc as nhom,";			
			sql+=" substr(trim(mtm),6,length(trim(mtm))) as tmtm, substr(trim(mtm),0,4) as muc,";
			sql+=" substr(trim(mtm),6,4) as tm,";	
			sql+= "case when c.stk like '" + s_sotk + "%' then b.stien else 0 end as no,";
			sql+= "case when d.stk like '" + s_sotk + "%' then b.stien else 0 end as co,";
			sql+=" 0 as sodu_no,0 as sodu_co";
			sql+=" from "+a.user+".a_ct" + s_yy +" a inner join "+a.user+".a_ctct" + s_yy + " b on a.id=b.idct";
			sql+=" left join "+a.user+".a_dmtk c on b.tknoa=c.id";
			sql+=" left join "+a.user+".a_dmtk d on b.tkcoa=d.id";

			if(s_IDMuc!="")sql+=" inner join "+a.user+".a_dmch g on (g.id=b.mtmno or g.id=mtmco)";
			else sql+=" left join "+a.user+".a_dmch g on (g.id=b.mtmno or g.id=mtmco)";

			//sql+=" left join "+a.user+".a_dmch g on (g.id=b.mtmno or g.id=b.mtmco)";
			sql+= "where (c.stk like '" + s_sotk + "%' or d.stk like '" + s_sotk + "%') ";
			sql+= "and b.tonghop=1";			
			if(s_IDlk!="")sql+=" and b.lk=" + s_IDlk + " ";
			if(s_IDMuc!="")sql+= "and g.mtm like '" + s_IDMuc+ "%'";			
			if (b_Checkngay) sql+=" and to_date(to_char(a.ngayg,'dd/mm/yyyy'),'dd/mm/yyyy') between to_date('"+s_Tungay+"','dd/mm/yyyy') and to_date('"+s_Denngay+"','dd/mm/yyyy')";
			else sql+=" and a.thanggs between '"+s_mm+"' and '"+s_mm1+"'";
			//
			if(s_IDChuong!="")sql+=" and a.chuong="+s_IDChuong;
			if(s_IDHoatdong!="")sql+=" and a.hoatdong="+s_IDHoatdong;	
			if(s_IDNhombc!="")sql+=" and a.idbc="+s_IDNhombc;
			//
			
			sql+= "order by g.stk,a.thanggs,a.ngayg,a.soctg";
			sql+=" ) t1 left join (select ch.mtm as muc,ch.ttk as tenmuc from a_dmch ch where cd=3) t2 on t1.muc=t2.muc";
			sql+=" ) tb1 left join (select substr(trim(ch.mtm),6,4) as tm,ch.ttk as tentm from a_dmch ch where cd=2) tb2 on tb1.tm=tb2.tm";
			sql+=" ) ttb1 left join (select substr(trim(ch.mtm),6,length(trim(mtm))) as tmtm,ch.ttk as tentmtm from a_dmch ch where cd=1) ttb2 on ttb1.tmtm=ttb2.tmtm";
			//tinh luy ke
			int tuthang = Convert.ToInt32(s_mm);
			int denthang = Convert.ToInt32(s_mm1);			
			//string sql_lk="";
			//sql_lk=a.get_FSluykenam_muc(s_yy,tuthang,s_sotk,s_IDMuc,s_IDlk,s_IDChuong,s_IDHoatdong,s_IDNhombc);//b_CheckChuong,s_IDChuong,b_CheckHoatDong,s_IDHoatDong,s_IDNhombc,b_CheckNhombc);
			//ds_Data2=a.get_data(sql_lk);
			//tinh so du dau ky			
			string sql_dk = "";
			sql_dk=a.get_SdDauKy_muc(s_yy,s_mm,s_sotk,s_IDMuc,s_IDlk,s_IDChuong,s_IDHoatdong,s_IDNhombc);//b_CheckChuong,s_IDChuong,b_CheckHoatDong,s_IDHoatDong,s_IDNhombc,b_CheckNhombc);
			ds_Data3=a.get_data(sql_dk);
			try
			{
				ds_Data=a.get_data(sql);				
//				if ((ds_Data==null || ds_Data.Tables[0].Rows.Count<=0)) flag_dsnull=true;
//				else
//				{
					//ds_Data=a.get_data(sql,sql_dk,sql_lk);
				//if(ds_Data2!=null)
					//ds_Data.Merge(ds_Data2);
			//	ds_Data.AcceptChanges();
				if(ds_Data3!=null)
					ds_Data.Merge(ds_Data3);
				ds_Data.AcceptChanges();
//				}
				if ((ds_Data==null || ds_Data.Tables[0].Rows.Count<=0)) flag_dsnull=true;		
				ds_Data.WriteXml("..\\xml\\KT_SoChiDuAn.xml",XmlWriteMode.WriteSchema);
			}
			catch
			{
				flag_dsnull=true;
			}			
			if (flag_dsnull) return null;
			else return ds_Data;
		}
		private string fs_soTheoDoiNguonKP(LibKetoan.AccessData a, string s_IDlk,string s_IDMuc,string s_yy, bool b_Checkngay, string s_mm, string s_mm1,string s_Tungay,string s_Denngay, string s_IDChuong,string s_IDHoatDong, string s_IDNhombc,string s_IDNguon)
		{
			#region thong ke chung tu
			sql="";
			sql="select to_char(a.ngaygs, 'dd/mm/yy') as ngaygs,";
			sql+=" to_char(a.ngayg, 'dd/mm/yy') as ngayct, a.soctg as";
			sql+=" soctg, b.noidung as diengiai,b.stien as stien, a.nghiepvu as nghiepvu,";
			sql+=" c.stk as stkno, d.stk as stkco, f.nhom as nhmuc, substr(trim(e.mtm),0,4) as muc";
			sql+=" from "+a.user+".a_ct"+ s_yy+" a inner join "+a.user+".a_ctct"+ s_yy +" b on a.id= b.idct";
			sql+=" inner join "+a.user+".a_dmtk c on b.tknoa= c.id";
			sql+=" inner join "+a.user+".a_dmtk d on b.tkcoa= d.id";
			sql+=" inner join "+a.user+".a_dmng g on (substr(trim(c.stk),7,length(trim(c.stk)))=g.mang";
			sql+=" or substr(trim(d.stk),7,length(trim(d.stk)))=g.mang";			
			sql+=" or substr(trim(c.stk),6,length(trim(c.stk)))=g.mang";
			sql+=" or substr(trim(d.stk),6,length(trim(d.stk)))=g.mang)";
			sql+=" left join "+a.user+".a_dmch e on e.id = b.mtmno or e.id = b.mtmco";
			sql+=" left join "+a.user+".a_dmnhom f on e.nhmuc=f.id";
			//sql+=" from , ";
			//sql+=" , , , ";
			sql+=" where g.id = " +s_IDNguon;
			if(s_IDHoatDong=="1")
			{
				sql+=" and (c.stk like '46111%' or c.stk like '46121%' or c.stk like '66111%'or c.stk like '66121%'";				
				sql+=" or d.stk like '46111%' or d.stk like '46121%' or d.stk like '66111%'or d.stk like '66121%')";
			}
			else
				if(s_IDHoatDong=="2")
			{
				sql+=" and (c.stk like '46112%' or c.stk like '46122%' or c.stk like '66112%' or c.stk like '66122%'";
				sql+=" or d.stk like '46112%' or d.stk like '46122%' or d.stk like '66112%' or d.stk like '66122%')";
				
			}
			else
				if(s_IDHoatDong=="0")
			{
				sql+=" and(c.stk like '662%' or c.stk like '462%'";
				sql+=" or d.stk like '662%' or d.stk like '462%')";
			}			
			if(s_IDlk!="")sql+=" and b.lk="+s_IDlk;			
			if(s_IDMuc!="")sql+= "and e.mtm like '" + s_IDMuc+"%'";
			if(s_IDChuong!="")sql+=" and a.chuong="+s_IDChuong;
			if(s_IDHoatDong!="")sql+=" and a.hoatdong="+s_IDHoatDong;			
			if(s_IDNhombc!="")sql+=" and a.idbc="+s_IDNhombc;			
			if (b_Checkngay) sql+=" and to_date(to_char(a.ngayg,'dd/mm/yyyy'),'dd/mm/yyyy') between to_date('"+s_Tungay+"','dd/mm/yyyy') and to_date('"+s_Denngay+"','dd/mm/yyyy')";
			else sql+=" and a.thanggs between '"+s_mm+"' and '"+s_mm1+"'";		
			
			#endregion ket thuc thong ke chung tu

			return sql;
		}
		public System.Data.DataSet soTheoDoiNguonKP(LibKetoan.AccessData a, string s_IDlk,string s_IDMuc,string s_yy, bool b_Checkngay, string s_mm, string s_mm1,string s_Tungay,string s_Denngay, string s_IDChuong,string s_IDHoatDong, string s_IDNhombc,string s_IDNguon)
		{					
			#region tinh so du
			string sql_sd="";
			sql_sd= "select sum(a.sdno" + s_mm + ") as no, sum(a.sdco" + s_mm + ") as co,b.stk as stk" ;
			sql_sd+=" from "+a.user+".a_sd" + s_yy + " a inner join "+a.user+".a_dmtk b on a.stka= b.id";
			sql_sd+=" inner join "+a.user+".a_dmng c on (substr(trim(b.stk),7,length(trim(b.stk)))=c.mang";
			sql_sd+=" or substr(trim(b.stk),6,length(trim(b.stk)))=c.mang)";			
			//sql_sd+=" inner join ";
			//sql_sd+=" , ,";
			sql_sd+=" where c.id = " +s_IDNguon;
			if(s_IDHoatDong=="1")
			{
				sql_sd+=" and (b.stk like '46111%' or b.stk like '46121%' or b.stk like '66111%'or b.stk like '66121%')";				
			}
			else
				if(s_IDHoatDong=="2")
			{
				sql_sd+=" and (b.stk like '46112%' or b.stk like '46122%' or b.stk like '66112%' or b.stk like '66122%')";				
			}
			else
				if(s_IDHoatDong=="0")
				sql_sd+=" and (b.stk like '462%' or b.stk like '662%')";
			//if(s_IDNguon!="")sql_sd+=" and ;
			if(s_IDlk!="")sql_sd+=" and a.lk=" + s_IDlk + " ";
			if(s_IDChuong!="")sql_sd+=" and a.chuong="+s_IDChuong;
			if(s_IDHoatDong!="")sql_sd+=" and a.hoatdong="+s_IDHoatDong;			
			if(s_IDNhombc!="")sql_sd+=" and a.idbc="+s_IDNhombc;
			sql_sd += " GROUP BY b.stk";				
			#endregion dong tinh so du
			try
			{
				ds_Data2=a.get_data(sql_sd);				
				//if ((ds_Data2==null || ds_Data2.Tables[0].Rows.Count<=0)) flag_dsnull=true;				
			}
			catch
			{
				flag_dsnull=true;
			}
			decimal l_sddk=0;
			Decimal fslk_no=0,fslk_co=0;
			if(flag_dsnull!=true || ds_Data2!=null || ds_Data2.Tables[0].Rows.Count>0)
			{
				//them cot so du dau ky
				ds_Data2.Tables[0].Columns.Add("sddk",typeof(System.Decimal));
				//them 1 dong fslk
				ds_Data2.Tables[0].Columns.Add("fslk_no",typeof(System.Decimal));
				ds_Data2.Tables[0].Columns.Add("fslk_co",typeof(System.Decimal));
				decimal l_sdno_tk461or462=0,l_sdco_tk461or462=0;
				decimal l_sdno_tk661or662=0,l_sdco_tk661or662=0;
				decimal l_sdco=0,l_sdno=0;
				string stk="";
				int countRow_sd=ds_Data2.Tables[0].Rows.Count;
				for(int j=0;j<=countRow_sd-1;j++)
				{
					stk=ds_Data2.Tables[0].Rows[j]["stk"].ToString();
					l_sdco=Convert.ToDecimal(ds_Data2.Tables[0].Rows[j]["co"].ToString());
					l_sdno=Convert.ToDecimal(ds_Data2.Tables[0].Rows[j]["no"].ToString());
					if(stk.Trim().Length>=3 && stk.Trim().Substring(0,3)=="461"||stk.Trim().Substring(0,3)=="462")
					{
						l_sdno_tk461or462+=l_sdno;
						l_sdco_tk461or462+=l_sdco;
					}
					else if(stk.Trim().Length>=3 && stk.Trim().Substring(0,3)=="661"||stk.Trim().Substring(0,3)=="662")
					{
						l_sdco_tk661or662+=l_sdco;
						l_sdno_tk661or662+=l_sdno;
					}				
					l_sddk=(l_sdco_tk461or462-l_sdno_tk461or462)-(l_sdno_tk661or662-l_sdco_tk661or662);					
				}
				ds_Data2.AcceptChanges();
			}
			try
			{
				//tinh chung tu phat sinh.
				sql=fs_soTheoDoiNguonKP(a,s_IDlk,s_IDMuc,s_yy,b_Checkngay,s_mm,s_mm1,s_Tungay,s_Denngay,s_IDChuong,s_IDHoatDong,s_IDNhombc,s_IDNguon);
				ds_Data=a.get_data(sql);				
				//if ((ds_Data==null || ds_Data.Tables[0].Rows.Count<=0)) flag_dsnull=true;	
			}
			catch{flag_dsnull=true;};
			if(flag_dsnull!=true || ds_Data!=null||ds_Data.Tables[0].Rows.Count>0)
			{
				//them mot so cot vao Table[0]
				ds_Data.Tables[0].Columns.Add("l_kpThucNhan_02",typeof(System.Decimal));
				ds_Data.Tables[0].Columns.Add("l_KPDNQT_04",typeof(System.Decimal));
				ds_Data.Tables[0].Columns.Add("l_KPGiam_05",typeof(System.Decimal));
				ds_Data.Tables[0].Columns.Add("l_congfs_01",typeof(System.Decimal));
				ds_Data.Tables[0].Columns.Add("l_congfs_02",typeof(System.Decimal));
				ds_Data.Tables[0].Columns.Add("l_congfs_03",typeof(System.Decimal));
				ds_Data.Tables[0].Columns.Add("l_congfs_04",typeof(System.Decimal));
				ds_Data.Tables[0].Columns.Add("l_congfs_05",typeof(System.Decimal));
				ds_Data.Tables[0].Columns.Add("l_congfs_06",typeof(System.Decimal));
				//kiem tra du lieu do vao cot thich hop
				string s_nghiepvu="", s_tkno="", s_tkco="";
				decimal l_tien=0,l_kpThucNhan_02=0,l_congfs_02=0;
				decimal l_KPDNQT_04=0,l_congfs_04=0,l_KPGiam_05=0,l_congfs_05=0;
				decimal l_congfs_01=0,l_congfs_03=0,l_congfs_06=0;
				int countRow=ds_Data.Tables[0].Rows.Count;
			
				for(int i=0;i<=countRow-1;i++)
				{		
					l_kpThucNhan_02=0;//l_congfs_02=0;
					l_KPDNQT_04=0;//l_congfs_04=0;
					l_KPGiam_05=0;//l_congfs_05=0;
					//l_congfs_01=0;l_congfs_03=0;l_congfs_06=0;

					s_nghiepvu=ds_Data.Tables[0].Rows[i]["nghiepvu"].ToString();
					s_tkno=ds_Data.Tables[0].Rows[i]["stkno"].ToString();
					s_tkco=ds_Data.Tables[0].Rows[i]["stkco"].ToString();
					l_tien=Convert.ToDecimal(ds_Data.Tables[0].Rows[i]["stien"].ToString());
					if(s_tkno.Trim().Length>=4 && s_tkno.Trim().Substring(0,4)=="4612" && s_nghiepvu!="8")
					{
						l_KPGiam_05+=l_tien;
						l_congfs_05+=l_KPGiam_05;
					}
					if(s_tkco.Trim().Length>=4 && s_tkco.Trim().Substring(0,4)=="4612")
					{
						l_kpThucNhan_02+=l_tien;
						l_congfs_02+=l_kpThucNhan_02;
					}
					if(s_tkno.Trim().Length>=4 && s_tkno.Trim().Substring(0,4)=="4612" && s_nghiepvu=="8")
					{
						l_kpThucNhan_02+=l_tien*(-1);
						l_congfs_02+=l_kpThucNhan_02;
					}
					if(s_tkno.Trim().Length>=4 && s_tkno.Trim().Substring(0,4)=="6612")
					{
						l_KPDNQT_04+=l_tien;
						l_congfs_04+=l_KPDNQT_04;
					}
					if(s_tkco.Trim().Length>=4 && s_tkco.Trim().Substring(0,4)=="6612")
					{
						l_KPDNQT_04+=l_tien*(-1);
						l_congfs_04+=l_KPDNQT_04;
					}
					ds_Data.Tables[0].Rows[i]["l_kpThucNhan_02"]=l_kpThucNhan_02;
					ds_Data.Tables[0].Rows[i]["l_KPDNQT_04"]=l_KPDNQT_04;
					ds_Data.Tables[0].Rows[i]["l_KPGiam_05"]=l_KPGiam_05;
				}
				l_congfs_03=l_sddk+l_congfs_02;
				l_congfs_06=l_congfs_03-l_congfs_04-l_congfs_05;	
			
				try
				{
					//tinh luy ke.
					string s_tungay="01/01/"+s_yy+"",sql_lk="";
					sql_lk=fs_soTheoDoiNguonKP(a,s_IDlk,s_IDMuc,s_yy,b_Checkngay,"01",s_mm1,s_tungay,s_Denngay,s_IDChuong,s_IDHoatDong,s_IDNhombc,s_IDNguon);
					ds_Data3=a.get_data(sql_lk);				
					//if ((ds_Data==null || ds_Data.Tables[0].Rows.Count<=0)) flag_dsnull=true;	
				}
				catch{flag_dsnull=true;};
				if(flag_dsnull!=true || ds_Data3!=null||ds_Data3.Tables[0].Rows.Count>0)
				{
					//them mot so cot vao Table[0]
					ds_Data3.Tables[0].Columns.Add("l_conglk_02",typeof(System.Decimal));
					ds_Data3.Tables[0].Columns.Add("l_conglk_04",typeof(System.Decimal));
					ds_Data3.Tables[0].Columns.Add("l_conglk_05",typeof(System.Decimal));
					//kiem tra du lieu do vao cot thich hop
					string s_lknghiepvu="", s_lktkno="", s_lktkco="";
					decimal l_lktien=0,l_lkkpThucNhan_02=0,l_conglk_02=0;
					decimal l_lkKPDNQT_04=0,l_conglk_04=0,l_lkKPGiam_05=0,l_conglk_05=0;
					//decimal l_conglk_01=0,l_conglk_03=0,l_conglk_06=0;
					int countRow_lk=ds_Data3.Tables[0].Rows.Count;
			
					for(int lk=0;lk<=countRow_lk-1;lk++)
					{		
						l_lkkpThucNhan_02=0;l_conglk_02=0;
						l_lkKPDNQT_04=0;l_conglk_04=0;l_lkKPGiam_05=0;l_conglk_05=0;
						s_lknghiepvu=ds_Data3.Tables[0].Rows[lk]["nghiepvu"].ToString();
						s_lktkno=ds_Data3.Tables[0].Rows[lk]["stkno"].ToString();
						s_lktkco=ds_Data3.Tables[0].Rows[lk]["stkco"].ToString();
						l_lktien=Convert.ToDecimal(ds_Data3.Tables[0].Rows[lk]["stien"].ToString());
						if(s_lktkno.Trim().Length>=4 && s_lktkno.Trim().Substring(0,4)=="4612" && s_lknghiepvu!="8")
						{
							l_lkKPGiam_05+=l_lktien;
							l_conglk_05+=l_lkKPGiam_05;
						}
						if(s_lktkco.Trim().Length>=4 && s_lktkco.Trim().Substring(0,4)=="4612")
						{
							l_lkkpThucNhan_02+=l_lktien;
							l_conglk_02+=l_lkkpThucNhan_02;
						}
						if(s_lktkno.Trim().Length>=4 && s_lktkno.Trim().Substring(0,4)=="4612" && s_lknghiepvu=="8")
						{
							l_lkkpThucNhan_02+=l_lktien*(-1);
							l_conglk_02+=l_lkkpThucNhan_02;
						}
						if(s_lktkno.Trim().Length>=4 && s_lktkno.Trim().Substring(0,4)=="6612")
						{
							l_lkKPDNQT_04+=l_lktien;
							l_conglk_04+=l_lkKPDNQT_04;
						}
						if(s_lktkco.Trim().Length>=4 && s_lktkco.Trim().Substring(0,4)=="6612")
						{
							l_lkKPDNQT_04+=l_lktien*(-1);
							l_conglk_04+=l_lkKPDNQT_04;
						}
						ds_Data3.Tables[0].Rows[lk]["l_conglk_02"]=l_conglk_02;
						ds_Data3.Tables[0].Rows[lk]["l_conglk_04"]=l_conglk_04;
						ds_Data3.Tables[0].Rows[lk]["l_conglk_05"]=l_conglk_05;

						
					}
				}
				if(ds_Data2!=null)
					ds_Data.Merge(ds_Data2);
				ds_Data.AcceptChanges();
				if(ds_Data3!=null)
					ds_Data.Merge(ds_Data3);
				ds_Data.AcceptChanges();
				try
				{
					int countRow_merge=ds_Data.Tables[0].Rows.Count;
					ds_Data.Tables[0].Rows[countRow_merge-1]["l_congfs_01"]=l_congfs_01;
					ds_Data.Tables[0].Rows[countRow_merge-1]["l_congfs_02"]=l_congfs_02;
					ds_Data.Tables[0].Rows[countRow_merge-1]["l_congfs_03"]=l_congfs_03;
					ds_Data.Tables[0].Rows[countRow_merge-1]["l_congfs_04"]=l_congfs_04;
					ds_Data.Tables[0].Rows[countRow_merge-1]["l_congfs_05"]=l_congfs_05;
					ds_Data.Tables[0].Rows[countRow_merge-1]["l_congfs_06"]=l_congfs_06;
					ds_Data.Tables[0].Rows[countRow_merge-1]["sddk"]=l_sddk;				
					//				ds_Data.Tables[0].Rows[countRow_merge-1]["fslk_no"]=fslk_no;
					//				ds_Data.Tables[0].Rows[countRow_merge-1]["fslk_co"]=fslk_co;
					ds_Data.AcceptChanges();				
				}
				catch{flag_dsnull=true;};
			}
			try
			{			
			
				if ((ds_Data==null || ds_Data.Tables[0].Rows.Count<=0)) flag_dsnull=true;
				//ds_Data.WriteXml("..\\xml\\KT_TheoDoiNguonKP.xml",XmlWriteMode.WriteSchema);
			}
			catch{};
			if (flag_dsnull) return null;
			else return ds_Data;
		}
		private string fs_soTongHopNguonKP(LibKetoan.AccessData a, string s_sotk,string s_IDlk, string s_Tungay, string s_Denngay, string s_mm, string s_mm1, string s_yy, string s_yyyy, bool b_Checkngay, string s_IDChuong,  string s_IDHoatDong, string s_IDMuc, string s_IDNhombc, string s_IDNguon)
		{
			//chung tu phat sinh
			sql="select e.lk as lk, substr(trim(e.lk),0,3) as loai,substr(trim(e.lk),5,3) as khoan,";
			sql+=" f.nhom as nhommuc,substr(trim(h.mtm),0,4) as muc,";
			sql+=" f.nhom as nhommuc,substr(trim(h.mtm),6,4) as tm,";
			sql+=" a.nghiepvu as nvu,c.stk as tkno, d.stk as tkco,null as tksd,";
			sql+=" case when (c.stk like '461%' or c.stk like '661%') then b.stien else 0 end as no,";
			sql+=" case when (d.stk like '461%' or d.stk like '661%') then b.stien else 0 end as co,";
			sql+=" 0 as l_kpThucNhan_02, 0 as l_KPDNQT_04,0 as l_KPGiam_05,0 as sddk";
			sql+=" from "+a.user+".a_ct"+s_yy+" a inner join "+a.user+".a_ctct"+s_yy+" b on a.id= b.idct";
			sql+=" inner join "+a.user+".a_dmtk c on b.tknoa= c.id";
			sql+=" inner join "+a.user+".a_dmtk d on b.tkcoa= d.id";
			sql+=" inner join "+a.user+".a_dmng g on (substr(trim(c.stk),7,length(trim(c.stk)))=g.mang";
			sql+=" or substr(trim(c.stk),6,length(trim(c.stk)))=g.mang";
			sql+=" or substr(trim(d.stk),7,length(trim(d.stk)))=g.mang";
			sql+=" or substr(trim(d.stk),6,length(trim(d.stk)))=g.mang)";
			sql+=" inner join "+a.user+".a_dmlk e on b.lk=e.id";
			sql+=" left join "+a.user+".a_dmch h on (b.mtmno=h.id or b.mtmco=h.id)";
			sql+=" left join "+a.user+".a_dmnhom f on h.nhmuc=f.id";			
			sql+=" where g.id="+s_IDNguon;
			if(s_IDHoatDong=="1")
			{
				sql+=" and (c.stk like '46111%' or c.stk like '46121%' or c.stk like '66111%'or c.stk like '66121%'";				
				sql+=" or d.stk like '46111%' or d.stk like '46121%' or d.stk like '66111%'or d.stk like '66121%')";
			}
			else
				if(s_IDHoatDong=="2")
			{
				sql+=" and (c.stk like '46112%' or c.stk like '46122%' or c.stk like '66112%' or c.stk like '66122%'";
				sql+=" or d.stk like '46112%' or d.stk like '46122%' or d.stk like '66112%' or d.stk like '66122%')";
			}
			else
				if(s_IDHoatDong=="0")
			{
				sql+=" and (c.stk like '462%' or c.stk like '662%'";
				sql+=" or d.stk like '462%' or d.stk like '662%')";
			}			
			if(s_IDlk!="")sql+=" and b.lk=" + s_IDlk+"";
			if (b_Checkngay) sql+=" and to_date(to_char(a.ngayg,'dd/mm/yyyy'),'dd/mm/yyyy') between to_date('"+s_Tungay+"','dd/mm/yyyy') and to_date('"+s_Denngay+"','dd/mm/yyyy')";
			else sql+=" and a.thanggs between '"+s_mm+"' and '"+s_mm1+"'";
			if(s_IDMuc!="")sql+= " and h.mtm like '" + s_IDMuc+"%'";
			if(s_IDChuong!="")sql+=" and a.chuong="+s_IDChuong;
			if(s_IDHoatDong!="")sql+=" and a.hoatdong="+s_IDHoatDong;			
			if(s_IDNhombc!="")sql+=" and a.idbc="+s_IDNhombc;
			return sql;
		}
		public System.Data.DataSet soTongHopNguonKP(LibKetoan.AccessData a, string s_sotk,string s_IDlk, string s_Tungay, string s_Denngay, string s_mm, string s_mm1, string s_yy, string s_yyyy, bool b_Checkngay, string s_IDChuong,  string s_IDHoatDong, string s_IDMuc, string s_IDNhombc, string s_IDNguon)
		{
			//TINH SO DU
			string sql_sd="";
			sql_sd+=" select e.lk as lk, substr(trim(e.lk),0,3) as loai,substr(trim(e.lk),5,3) as khoan,";
			sql_sd+=" f.nhom as nhommuc,substr(trim(d.mtm),0,4) as muc,";
			sql_sd+=" f.nhom as nhommuc,substr(trim(d.mtm),6,4) as tm,";
			sql_sd+=" a.nghiepvu as nvu,null,null, b.stk,sum(a.sdno" + s_mm +") as no,";
			sql_sd+=" sum(a.sdco" +s_mm +") as co, ";
			sql_sd+=" 0 as l_kpThucNhan_02, 0 as l_KPDNQT_04,0 as l_KPGiam_05,0 as sddk";
			sql_sd+=" from "+a.user+".a_sd" + s_yy + " a inner join "+a.user+".a_dmtk b on a.stka= b.id";
			sql_sd+=" inner join "+a.user+".a_dmng c on (substr(trim(b.stk),7,length(trim(b.stk)))=c.mang";
			sql_sd+=" or substr(trim(b.stk),6,length(trim(b.stk)))=c.mang)";			
			sql_sd+=" inner join "+a.user+".a_dmlk e on a.lk=e.id";
			sql_sd+=" left join "+a.user+".a_dmch d on a.mtmuc=d.id";
			sql_sd+=" left join "+a.user+".a_dmnhom f on d.nhmuc=f.id";			
			sql_sd+=" where c.id =" + s_IDNguon;
			if(s_IDHoatDong=="1")
			{
				sql_sd+=" and (b.stk like '46111%' or b.stk like '46121%' or b.stk like '66111%'or b.stk like '66121%')";				
			}
			else
				if(s_IDHoatDong=="2")
			{
				sql_sd+=" and (b.stk like '46112%' or b.stk like '46122%' or b.stk like '66112%' or b.stk like '66122%')";				
			}
			else
				if(s_IDHoatDong=="0")
				sql_sd+=" and (b.stk like '462%' or b.stk like '662%')";			
			if(s_IDlk!="")sql_sd+=" and e.id=" +s_IDlk + "";			
			if(s_IDMuc!="")sql_sd+= " and d.mtm like '" + s_IDMuc+"%'";
			if(s_IDChuong!="")sql_sd+=" and a.chuong="+s_IDChuong;
			if(s_IDHoatDong!="")sql_sd+=" and a.hoatdong="+s_IDHoatDong;			
			if(s_IDNhombc!="")sql_sd+=" and a.idbc="+s_IDNhombc;
			sql_sd+=" group by e.lk,f.nhom,d.mtm,b.stk,a.nghiepvu";
			sql_sd+=" order by muc";
			try
			{
				ds_Data2=a.get_data(sql_sd);				
				//if ((ds_Data2==null || ds_Data2.Tables[0].Rows.Count<=0)) flag_dsnull=true;				
			}
			catch
			{
				flag_dsnull=true;
			}
			decimal l_sddk=0;			
			if(flag_dsnull!=true || ds_Data2!=null || ds_Data2.Tables[0].Rows.Count>0)
			{
				//them cot so du dau ky
				//ds_Data2.Tables[0].Columns.Add("sddk",typeof(System.Decimal));
				//them 1 dong fslk
				ds_Data2.Tables[0].Columns.Add("fslk_no",typeof(System.Decimal));
				ds_Data2.Tables[0].Columns.Add("fslk_co",typeof(System.Decimal));
				decimal l_sdno_tk461or462=0,l_sdco_tk461or462=0;
				decimal l_sdno_tk661or662=0,l_sdco_tk661or662=0;
				decimal l_sdco=0,l_sdno=0;
				string stk="";
				int countRow_sd=ds_Data2.Tables[0].Rows.Count;
				for(int j=0;j<=countRow_sd-1;j++)
				{
					stk=ds_Data2.Tables[0].Rows[j]["stk"].ToString();
					l_sdco=Convert.ToDecimal(ds_Data2.Tables[0].Rows[j]["co"].ToString());
					l_sdno=Convert.ToDecimal(ds_Data2.Tables[0].Rows[j]["no"].ToString());
					if(stk.Trim().Length>=3 && stk.Trim().Substring(0,3)=="461"||stk.Trim().Substring(0,3)=="462")
					{
						l_sdno_tk461or462+=l_sdno;
						l_sdco_tk461or462+=l_sdco;
					}
					else if(stk.Trim().Length>=3 && stk.Trim().Substring(0,3)=="661"||stk.Trim().Substring(0,3)=="662")
					{
						l_sdco_tk661or662+=l_sdco;
						l_sdno_tk661or662+=l_sdno;
					}				
					l_sddk=(l_sdco_tk461or462-l_sdno_tk461or462)-(l_sdno_tk661or662-l_sdco_tk661or662);	
					ds_Data2.Tables[0].Rows[countRow_sd-1]["sddk"]=l_sddk;
				}
				ds_Data2.AcceptChanges();
			}
			try
			{
				//tinh chung tu phat sinh.
				sql=fs_soTongHopNguonKP(a,s_sotk,s_IDlk,s_Tungay,s_Denngay,s_mm,s_mm1,s_yy,s_yyyy,b_Checkngay,s_IDChuong,s_IDHoatDong,s_IDMuc,s_IDNhombc,s_IDNguon);
				ds_Data=a.get_data(sql);				
				//if ((ds_Data==null || ds_Data.Tables[0].Rows.Count<=0)) flag_dsnull=true;	
			}
			catch{flag_dsnull=true;};
			if(flag_dsnull!=true || ds_Data!=null||ds_Data.Tables[0].Rows.Count>0)
			{
				//them mot so cot vao Table[0]
//				ds_Data.Tables[0].Columns.Add("l_kpThucNhan_02",typeof(System.Decimal));
//				ds_Data.Tables[0].Columns.Add("l_KPDNQT_04",typeof(System.Decimal));
//				ds_Data.Tables[0].Columns.Add("l_KPGiam_05",typeof(System.Decimal));
				//kiem tra du lieu do vao cot thich hop
				string s_nghiepvu="", s_tkno="", s_tkco="";
				decimal l_tienno=0,l_tienco=0,l_kpThucNhan_02=0;
				decimal l_KPDNQT_04=0,l_KPGiam_05=0;
				int countRow=ds_Data.Tables[0].Rows.Count;
			
				for(int i=0;i<=countRow-1;i++)
				{		
					l_kpThucNhan_02=0;
					l_KPDNQT_04=0;
					l_KPGiam_05=0;

					s_nghiepvu=ds_Data.Tables[0].Rows[i]["nvu"].ToString();
					s_tkno=ds_Data.Tables[0].Rows[i]["tkno"].ToString();
					s_tkco=ds_Data.Tables[0].Rows[i]["tkco"].ToString();
					l_tienno=Convert.ToDecimal(ds_Data.Tables[0].Rows[i]["no"].ToString());
					l_tienco=Convert.ToDecimal(ds_Data.Tables[0].Rows[i]["co"].ToString());
					if(s_tkno.Trim().Length>=4 && s_tkno.Trim().Substring(0,4)=="4612" && s_nghiepvu!="8")
					{
						l_KPGiam_05+=l_tienno;
					}
					if(s_tkco.Trim().Length>=4 && s_tkco.Trim().Substring(0,4)=="4612")
					{
						l_kpThucNhan_02+=l_tienco;
					}
					if(s_tkno.Trim().Length>=4 && s_tkno.Trim().Substring(0,4)=="4612" && s_nghiepvu=="8")
					{
						l_kpThucNhan_02+=l_tienno*(-1);
					}
					if(s_tkno.Trim().Length>=4 && s_tkno.Trim().Substring(0,4)=="6612")
					{
						l_KPDNQT_04+=l_tienno;
					}
					if(s_tkco.Trim().Length>=4 && s_tkco.Trim().Substring(0,4)=="6612")
					{
						l_KPDNQT_04+=l_tienco*(-1);
					}
					ds_Data.Tables[0].Rows[i]["l_kpThucNhan_02"]=l_kpThucNhan_02;
					ds_Data.Tables[0].Rows[i]["l_KPDNQT_04"]=l_KPDNQT_04;
					ds_Data.Tables[0].Rows[i]["l_KPGiam_05"]=l_KPGiam_05;
				}
				if(ds_Data2!=null)
					ds_Data.Merge(ds_Data2);
				ds_Data.AcceptChanges();
			}
			try
			{			
			
				if ((ds_Data==null || ds_Data.Tables[0].Rows.Count<=0)) flag_dsnull=true;
				//ds_Data.WriteXml("..\\xml\\KT_THNguonKP.xml",XmlWriteMode.WriteSchema);
			}
			catch{};
			if (flag_dsnull) return null;
			else return ds_Data;
		}
		private string tc_fsctkinhphihoatdong(LibKetoan.AccessData a,string s_IDlk,string s_mm, string s_mm1, string s_yy, string s_yyyy, string s_IDChuong,  string s_IDHoatDong, string s_IDMuc, string s_IDNhombc, string s_IDNguon)
		{
			sql=" select t1.*, t2.td_muc";
			sql+=" from (";
			sql+=" select lk.lk as lk, substr(trim(lk.lk),0,3) as loai,substr(trim(lk.lk),5,3) as khoan,";
			sql+=" nh.nhom as nhommuc,";
			sql+=" case when length(trim(ch.mtm))>3 then substr(trim(ch.mtm),0,4)else '' end as muc,";
			sql+=" case when length(trim(ch.mtm))>8 then substr(trim(ch.mtm),6,4)else '' end as tm,0 as sapxep,";
			sql+=" ch.ttk as chitieu,";
			sql+=" 0 as sd_no,0 as sd_co,";
			sql+=" ct.nghiepvu as nvu,tkno.stk as tkno, tkco.stk as tkco,null as tksd,";
			sql+=" case when (tkno.stk like '461%' or tkno.stk like '661%') then ctct.stien else 0 end as no,";
			sql+=" case when (tkco.stk like '461%' or tkco.stk like '661%') then ctct.stien else 0 end as co,";
			sql+=" 0 as cot2, 0 as cot5, 0 as cot7, 0 as lk2, 0 as lk5, 0 as lk7";
			
			sql+=" from "+a.user+".a_ct"+s_yy+" ct inner join "+a.user+".a_ctct"+s_yy+" ctct on ct.id= ctct.idct";
			sql+=" inner join "+a.user+".a_dmtk tkno on ctct.tknoa= tkno.id";
			sql+=" inner join "+a.user+".a_dmtk tkco on ctct.tkcoa=tkco.id";			

			sql+=" inner join "+a.user+".a_dmng ng on (substr(trim(tkno.stk), 7, length(trim(tkno.stk)))= ng.mang or substr(trim(tkco.stk), 7, length(trim(tkco.stk)))= ng.mang)";			
			sql+=" inner join "+a.user+".a_dmlk lk on ctct.lk=lk.id";
			sql+=" inner join "+a.user+".a_dmch ch on (ctct.mtmno=ch.id or ctct.mtmco=ch.id)";
			sql+=" inner join "+a.user+".a_dmnhom nh on (ch.nhmuc=nh.id or ch.nhmuc=nh.id)";
			
			sql+=" where ng.id="+s_IDNguon+"";
			if(s_IDlk!="")sql+=" and ctct.lk=" + s_IDlk+"";

			if (s_mm !="" || s_mm1!="")
				sql += " AND ct.thanggs BETWEEN "+ s_mm + " AND " + s_mm1;		
			if(s_IDMuc!="")sql+= " and ch.mtm like '" + s_IDMuc+"%'";
			if(s_IDChuong!="")sql+=" and ct.chuong="+s_IDChuong;
			if(s_IDHoatDong!="")sql+=" and ct.hoatdong="+s_IDHoatDong;			
			if(s_IDNhombc!="")sql+=" and ct.idbc="+s_IDNhombc;
			sql+=" ) t1";
			sql+=" left join (select mtm as muc, ttk as td_muc from "+a.user+".a_dmch) t2 on t2.muc=t1.muc";
			return sql;
		}
		public System.Data.DataSet tc_ctkinhphihoatdong(LibKetoan.AccessData a,string s_IDlk,string s_mm, string s_mm1, string s_yy, string s_yyyy, string s_IDChuong,  string s_IDHoatDong, string s_IDMuc, string s_IDNhombc, string s_IDNguon)
		{			
		    sql=tc_fsctkinhphihoatdong(a,s_IDlk,s_mm,s_mm1,s_yy,s_yyyy,s_IDChuong,s_IDHoatDong,s_IDMuc,s_IDNhombc,s_IDNguon);
			try
			{
				ds_Data=a.get_data(sql);
				if(ds_Data!=null && ds_Data.Tables[0].Rows.Count>0)
				{										
					//ds_Data.Tables[0].Columns.Add("sapxep",typeof(System.Decimal));
					//kiem tra du lieu do vao cot thich hop
					string s_nghiepvu="", s_tkno="", s_tkco="";
					decimal l_cot2co=0,l_cot2no=0,l_cot2=0,l_cot5co=0,l_cot5no=0,l_cot5=0,l_cot7=0, l_co=0,l_no=0;				
					int countRow=ds_Data.Tables[0].Rows.Count;
			
					for(int i=0;i<=countRow-1;i++)
					{					                  
						l_cot2=0;l_cot2co=0;l_cot2no=0;l_cot5=0;l_cot5co=0;l_cot5no=0;l_cot7=0;
						s_nghiepvu=ds_Data.Tables[0].Rows[i]["nvu"].ToString();
						s_tkno=ds_Data.Tables[0].Rows[i]["tkno"].ToString();
						s_tkco=ds_Data.Tables[0].Rows[i]["tkco"].ToString();
						//l_tien=Convert.ToInt32(ds_Data.Tables[0].Rows[i]["tien"].ToString());
						l_no=Convert.ToDecimal(ds_Data.Tables[0].Rows[i]["no"].ToString());
						l_co=Convert.ToDecimal(ds_Data.Tables[0].Rows[i]["co"].ToString());
						if(s_tkno!="" || s_tkco!="")
						{
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="461" && (s_nghiepvu=="8"||s_nghiepvu=="7"))
							{
								l_cot7+=l_no;
							}
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="461" && s_nghiepvu!="8" && s_nghiepvu!="7")
							{
								l_cot2co+=l_co;
							}
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="461" && s_nghiepvu!="8" && s_nghiepvu!="7")
							{
								l_cot2no+=l_no;
							}
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="661" && s_nghiepvu!="8"&&s_nghiepvu!="7")
							{
								l_cot5no+=l_no;
							}
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="661"&&s_nghiepvu!="8"&&s_nghiepvu!="7")
							{
								l_cot5co+=l_co;						
							}
							l_cot2=l_cot2co-l_cot2no;
							l_cot5=l_cot5no-l_cot5co;
						}
						ds_Data.Tables[0].Rows[i]["cot2"]=l_cot2;
						ds_Data.Tables[0].Rows[i]["cot5"]=l_cot5;
						ds_Data.Tables[0].Rows[i]["cot7"]=l_cot7;
						ds_Data.Tables[0].Rows[i]["sapxep"]=1;
					}	
				}
				//ds_Data.WriteXml("..\\xml\\KT_tc_CTkinhphihoatdong.xml",XmlWriteMode.WriteSchema);
				ds_Data2=a.get_SdDauKy_muc_tm(s_yy,s_mm,s_IDMuc,s_IDlk,s_IDChuong,s_IDHoatDong,s_IDNhombc,s_IDNguon);
				if(ds_Data2==null||ds_Data2.Tables[0].Rows.Count<=0)flag_dsnull=true;
				else
					ds_Data.Merge(ds_Data2);
				ds_Data.AcceptChanges();
				//tinh luy ke tu dau nam
				sql1=tc_fsctkinhphihoatdong(a,s_IDlk,"01",s_mm1,s_yy,s_yyyy,s_IDChuong,s_IDHoatDong,s_IDMuc,s_IDNhombc,s_IDNguon);
				ds_Data3=a.get_data(sql1);
				if(ds_Data3!=null && ds_Data3.Tables[0].Rows.Count>0)
				{	
					//					//tinh so lieu cho cac cot
					//					//them mot so cot vao Table[0]
					//					ds_Data.Tables[0].Columns.Add("lk2",typeof(System.Int32));
					//					ds_Data.Tables[0].Columns.Add("lk5",typeof(System.Int32));					
					//ds_Data3.Tables[0].Columns.Add("sapxep",typeof(System.Decimal));
					//kiem tra du lieu do vao cot thich hop
					string s_lknghiepvu="", s_lktkno="", s_lktkco="";
					decimal l_lkcot2co=0,l_lkcot2no=0,l_lkcot2=0,l_lkcot5co=0,l_lkcot5no=0,l_lkcot5=0,l_lkcot7=0, l_lkco=0,l_lkno=0;				
					//int countRow=ds_Data.Tables[0].Rows.Count;
					int count_=ds_Data3.Tables[0].Rows.Count;
					for(int j=0;j<=count_-1;j++)
					{					                  
						l_lkcot2=0;l_lkcot2co=0;l_lkcot2no=0;l_lkcot5=0;l_lkcot5co=0;l_lkcot5no=0;l_lkcot7=0;
						s_lknghiepvu=ds_Data3.Tables[0].Rows[j]["nvu"].ToString();
						s_lktkno=ds_Data3.Tables[0].Rows[j]["tkno"].ToString();
						s_lktkco=ds_Data3.Tables[0].Rows[j]["tkco"].ToString();
						//l_tien=Convert.ToInt32(ds_Data.Tables[0].Rows[i]["tien"].ToString());
						l_lkno=Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["no"].ToString());
						l_lkco=Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["co"].ToString());
						if(s_lktkno!="" || s_lktkco!="")
						{
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="461" && (s_lknghiepvu=="8"||s_lknghiepvu=="7"))
							{
								l_lkcot7+=l_lkno;
							}
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="461" && s_lknghiepvu!="8" && s_lknghiepvu!="7")
							{
								l_lkcot2co+=l_lkco;
							}
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="461" && s_lknghiepvu!="8" && s_lknghiepvu!="7")
							{
								l_lkcot2no+=l_lkno;
							}
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="661" && s_lknghiepvu!="8"&&s_lknghiepvu!="7")
							{
								l_lkcot5no+=l_lkno;
							}
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="661"&&s_lknghiepvu!="8"&&s_lknghiepvu!="7")
							{
								l_lkcot5co+=l_lkco;							
							}
							l_lkcot2=l_lkcot2co-l_lkcot2no;
							l_lkcot5=l_lkcot5no-l_lkcot5co;
						}
						ds_Data3.Tables[0].Rows[j]["lk2"]=l_lkcot2;
						ds_Data3.Tables[0].Rows[j]["lk5"]=l_lkcot5;
						ds_Data3.Tables[0].Rows[j]["lk7"]=l_lkcot7;
						ds_Data3.Tables[0].Rows[j]["sapxep"]=2;
					}							
				}
				//ds_Data3.WriteXml("..\\xml\\KT_tc_CTkinhphihoatdonglk.xml",XmlWriteMode.WriteSchema);
				ds_Data.Merge(ds_Data3);
				ds_Data.AcceptChanges();
				if(ds_Data==null || ds_Data.Tables[0].Rows.Count<=0)flag_dsnull=true;
				else flag_dsnull=false;
				ds_Data.WriteXml("..\\xml\\KT_tc_CTkinhphihoatdong.xml",XmlWriteMode.WriteSchema);					
			}
			catch{flag_dsnull=true;}				
			if(flag_dsnull)return null;			
			return ds_Data;
		}
		private string tc_fskinhphiduan(LibKetoan.AccessData a,string s_IDlk,string s_mm, string s_mm1, string s_yy, string s_yyyy, string s_IDChuong,  string s_IDHoatDong, string s_IDMuc, string s_IDNhombc, string s_IDNguon)
		{
			sql=" select t1.*, t2.td_muc";
			sql+=" from (";
			sql+=" select lk.lk as lk, substr(trim(lk.lk),0,3) as loai,substr(trim(lk.lk),5,3) as khoan,";
			sql+=" nh.nhom as nhommuc,";
			sql+=" case when length(trim(ch.mtm))>3 then substr(trim(ch.mtm),0,4)else '' end as muc,";
			sql+=" case when length(trim(ch.mtm))>8 then substr(trim(ch.mtm),6,4)else '' end as tm,";
			sql+=" ch.ttk as chitieu,";
			sql+=" ct.nghiepvu as nvu,tkno.stk as tkno, tkco.stk as tkco,null as tksd,";
			sql+=" case when (tkno.stk like '462%' or tkno.stk like '662%') then ctct.stien else 0 end as no,";
			sql+=" case when (tkco.stk like '462%' or tkco.stk like '662%') then ctct.stien else 0 end as co,";
			sql+=" 0 as cot021,0 as cot022, 0 as cot051,0 as cot052, 0 as cot041,0 as cot042,0 as sd,0 as sdn,0 as d_fs,0 as d_lk";			
			sql+=" from "+a.user+".a_ct"+s_yy+" ct inner join "+a.user+".a_ctct"+s_yy+" ctct on ct.id= ctct.idct";
			sql+=" inner join "+a.user+".a_dmtk tkno on ctct.tknoa= tkno.id";
			sql+=" inner join "+a.user+".a_dmtk tkco on ctct.tkcoa=tkco.id";			
			sql+=" inner join "+a.user+".a_dmch ch on (ctct.mtmno=ch.id or ctct.mtmco=ch.id)";
			sql+=" inner join "+a.user+".a_dmng ng on (substr(trim(tkno.stk), 7, length(trim(tkno.stk)))= ng.mang or substr(trim(tkco.stk), 7, length(trim(tkco.stk)))= ng.mang)";			
			sql+=" left join "+a.user+".a_dmlk lk on ctct.lk=lk.id";
			sql+=" left join "+a.user+".a_dmnhom nh on (ch.nhmuc=nh.id or ch.nhmuc=nh.id)";
			
			sql+=" where (tkno.stk like '462%' or tkno.stk like '662%' or tkco.stk like '662%' or  tkco.stk like '462%')";
			sql+=" and ng.id="+s_IDNguon+"";
			if(s_IDlk!="")sql+=" and ctct.lk=" + s_IDlk+"";

			if (s_mm !="" || s_mm1!="")
				sql += " AND ct.thanggs BETWEEN "+ s_mm + " AND " + s_mm1;		
			if(s_IDMuc!="")sql+= " and ch.mtm like '" + s_IDMuc+"%'";
			if(s_IDChuong!="")sql+=" and ct.chuong="+s_IDChuong;
			if(s_IDHoatDong!="")sql+=" and ct.hoatdong="+s_IDHoatDong;			
			if(s_IDNhombc!="")sql+=" and ct.idbc="+s_IDNhombc;
			sql+=" ) t1";
			sql+=" left join (select mtm as muc, ttk as td_muc from "+a.user+".a_dmch) t2 on t2.muc=t1.muc";
			return sql;			
		}
		public DataSet tc_ctkinhphiduan(LibKetoan.AccessData a,string s_IDlk,string s_mm, string s_mm1, string s_yy, string s_yyyy, string s_IDChuong,  string s_IDHoatDong, string s_IDMuc, string s_IDNhombc, string s_IDNguon)
		{			
			sql=tc_fskinhphiduan(a,s_IDlk,s_mm,s_mm1,s_yy,s_yyyy,s_IDChuong,s_IDHoatDong,s_IDMuc,s_IDNhombc,s_IDNguon);
			ds_Data=a.get_data(sql);
			try
			{
				if(ds_Data!=null && ds_Data.Tables[0].Rows.Count>0)//flag_dsnull = true;
				{
					//do du lieu cho bao cao II.1.kp da use 
					Decimal d_no=0,d_co=0,d_fs=0;
					//ds_Data.Tables[0].Columns.Add("d_fs",typeof(System.Decimal));
					int countR_fs=ds_Data.Tables[0].Rows.Count;
					for(int fs=0;fs<=countR_fs-1;fs++)
					{
						d_fs=0;
						d_no=Convert.ToDecimal(ds_Data.Tables[0].Rows[fs]["no"].ToString());
						d_fs+=d_no;
						d_co=Convert.ToDecimal(ds_Data.Tables[0].Rows[fs]["co"].ToString());
						d_fs+=d_co;
						ds_Data.Tables[0].Rows[fs]["d_fs"]=d_fs;
					}
				
					//do du lieu cho cac cot trong baocao I.Tinh hinh kinh phi
					//ds_Data.Tables[0].Columns.Add("sapxep",typeof(System.Int32));
					string s_nghiepvu="", s_tkno="", s_tkco="";
					decimal l_no=0,l_co=0;
					decimal l_cot021co=0,l_cot021no=0,l_cot041co=0,l_cot041no=0,l_cot051=0,l_cot021=0,l_cot041=0;				
					int countRow=ds_Data.Tables[0].Rows.Count;
		
					for(int i=0;i<=countRow-1;i++)
					{					                  
						l_cot021co=0;l_cot021no=0;l_cot041co=0;l_cot041no=0;l_cot051=0;l_cot021=0;l_cot041=0;
						s_nghiepvu=ds_Data.Tables[0].Rows[i]["nvu"].ToString();
						s_tkno=ds_Data.Tables[0].Rows[i]["tkno"].ToString();
						s_tkco=ds_Data.Tables[0].Rows[i]["tkco"].ToString();
						//l_tien=Convert.ToInt32(ds_Data.Tables[0].Rows[i]["tien"].ToString());
						l_no=Convert.ToDecimal(ds_Data.Tables[0].Rows[i]["no"].ToString());
						l_co=Convert.ToDecimal(ds_Data.Tables[0].Rows[i]["co"].ToString());
						if(s_tkno!="" || s_tkco!="")
						{
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_nghiepvu=="8")
							{
								l_cot051+=l_no;
							}
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462" && s_nghiepvu!="8")
							{
								l_cot021co+=l_co;
							}
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_nghiepvu!="8")
							{
								l_cot021no+=l_no;
							}
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662")
							{
								l_cot041no+=l_no;
							}
							if(s_tkno.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662")
							{
								l_cot041co+=l_co;							
							}
							l_cot021=l_cot021co-l_cot021no;
							l_cot041=l_cot041no-l_cot041co;
						}
						ds_Data.Tables[0].Rows[i]["cot021"]=l_cot021;
						ds_Data.Tables[0].Rows[i]["cot051"]=l_cot051;
						ds_Data.Tables[0].Rows[i]["cot041"]=l_cot041;
						//ds_Data.Tables[0].Rows[i]["sapxep"]=1;						
					}
				}
				//tinh so du dau ky
				ds_Data2=a.get_SdDauKy_muc_tmda(s_yy,s_mm,s_IDMuc,s_IDlk,s_IDChuong,s_IDHoatDong,s_IDNhombc,s_IDNguon);
				if(ds_Data2!=null)
					ds_Data.Merge(ds_Data2);
				ds_Data.AcceptChanges();
				//tinh so du dau nam
				ds_sdDaunam=a.get_SdDauKyNam_muc_tmda(s_yy,s_IDMuc,s_IDlk,s_IDChuong,s_IDHoatDong,s_IDNhombc,s_IDNguon);
				if(ds_sdDaunam!=null)
					ds_Data.Merge(ds_sdDaunam);
				ds_Data.AcceptChanges();
				//ds_Data.WriteXml("..\\xml\\KT_tc_ctkinhphiduansdn.xml",XmlWriteMode.WriteSchema);

				sql1=tc_fskinhphiduan(a,s_IDlk,"01",s_mm1,s_yy,s_yyyy,s_IDChuong,s_IDHoatDong,s_IDMuc,s_IDNhombc,s_IDNguon);
				ds_Data3=a.get_data(sql1);
				if(ds_Data3!=null && ds_Data3.Tables[0].Rows.Count>0)
				{
					//do du lieu cho II.1.kp da use
					Decimal d_nolk=0,d_colk=0,d_lk=0;
					//ds_Data3.Tables[0].Columns.Add("d_lk",typeof(System.Decimal));
					int countR_lk=ds_Data3.Tables[0].Rows.Count;
					for(int lk=0;lk<=countR_lk-1;lk++)
					{
						d_lk=0;
						d_nolk=Convert.ToDecimal(ds_Data3.Tables[0].Rows[lk]["no"].ToString());
						d_lk+=d_nolk;
						d_colk=Convert.ToDecimal(ds_Data3.Tables[0].Rows[lk]["co"].ToString());
						d_lk+=d_colk;
						ds_Data3.Tables[0].Rows[lk]["d_lk"]=d_lk;
					}
					//do du lieu cho I.tinh hinh kp
					//ds_Data3.Tables[0].Columns.Add("sapxep",typeof(System.Int32));
					string s_lknghiepvu="", s_lktkno="", s_lktkco="";
					decimal l_lkno=0,l_lkco=0;
					decimal l_cot022co=0,l_cot022no=0,l_cot042co=0,l_cot042no=0,l_cot052=0,l_cot022=0,l_cot042=0;				
					int countRow_=ds_Data3.Tables[0].Rows.Count;
		
					for(int j=0;j<=countRow_-1;j++)
					{					                  
						l_cot022co=0;l_cot022no=0;l_cot042co=0;l_cot042no=0;l_cot052=0;l_cot022=0;l_cot042=0;
						s_lknghiepvu=ds_Data3.Tables[0].Rows[j]["nvu"].ToString();
						s_lktkno=ds_Data3.Tables[0].Rows[j]["tkno"].ToString();
						s_lktkco=ds_Data3.Tables[0].Rows[j]["tkco"].ToString();
						//l_tien=Convert.ToInt32(ds_Data.Tables[0].Rows[i]["tien"].ToString());
						l_lkno=Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["no"].ToString());
						l_lkco=Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["co"].ToString());
						if(s_lktkno!="" || s_lktkco!="")
						{
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lknghiepvu=="8")
							{
								l_cot052+=l_lkno;
							}
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462" && s_lknghiepvu!="8")
							{
								l_cot022co+=l_lkco;
							}
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lknghiepvu!="8")
							{
								l_cot022no+=l_lkno;
							}
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662")
							{
								l_cot042no+=l_lkno;
							}
							if(s_lktkno.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662")
							{
								l_cot042co+=l_lkco;							
							}
							l_cot022=l_cot022co-l_cot022no;
							l_cot042=l_cot042no-l_cot042co;
						}
						ds_Data3.Tables[0].Rows[j]["cot022"]=l_cot022;
						ds_Data3.Tables[0].Rows[j]["cot052"]=l_cot052;
						ds_Data3.Tables[0].Rows[j]["cot042"]=l_cot042;
						//ds_Data3.Tables[0].Rows[j]["sapxep"]=2;						
					}
				}
				if(ds_Data3!=null)
					ds_Data.Merge(ds_Data3);
				ds_Data.AcceptChanges();
				if(ds_Data==null || ds_Data.Tables[0].Rows.Count<=0) flag_dsnull=true;
				else
					flag_dsnull=false;
				//ds_Data.WriteXml("..\\xml\\KT_tc_ctkinhphiduan.xml",XmlWriteMode.WriteSchema);				
			}
				//catch{flag_dsnull=true;};
			catch{flag_dsnull=true;};
			if (flag_dsnull) return null;
			else return ds_Data;
		}
		private string tc_fsmKPI(LibKetoan.AccessData a,string s_IDlk,string s_mm, string s_mm1, string s_yy, string s_yyyy, string s_IDChuong,  string s_IDHoatDong, string s_IDMuc, string s_IDNhombc, string s_IDNguon)
		{
			sql=" select lk.lk as lk, substr(trim(lk.lk),0,3) as loai,";
			sql+=" substr(trim(lk.lk),5,3) as khoan,";
			sql+=" case when (tkno.stk like '461%' or tkno.stk like '661%' or tkno.stk like '462%' or tkno.stk like '662%') then ctct.stien else 0 end as no,";
			sql+=" case when (tkco.stk like '461%' or tkco.stk like '661%' or tkco.stk like '462%' or tkco.stk like '662%') then ctct.stien else 0 end as co,";
			sql+=" tkno.stk as tkno,tkco.stk as tkco,ng.mang,nv.id as idnghiepvu,nv.ten as tennghiepvu,";
		
			sql+=" 0 as d302, 0 as d306, 0 as d308, 0 as d402, 0 as d406,0 as d408,";
			sql+=" 0 as d502, 0 as d506, 0 as d508, 0 as d602, 0 as d606,0 as d608,";
			sql+=" 0 as d312, 0 as d316, 0 as d318, 0 as d412, 0 as d416,0 as d418,";
			sql+=" 0 as d512, 0 as d516, 0 as d518, 0 as d612, 0 as d616,0 as d618,";
			sql+=" 0 as d302_, 0 as d306_, 0 as d308_, 0 as d402_, 0 as d406_,0 as d408_,";
			sql+=" 0 as d502_, 0 as d506_, 0 as d508_, 0 as d602_, 0 as d606_,0 as d608_,";
			sql+=" 0 as d802, 0 as d806, 0 as d808, 0 as d902, 0 as d906,0 as d908,";
			sql+=" 0 as d1002, 0 as d1006, 0 as d1008, 0 as d1102, 0 as d1106,0 as d1108,";
			sql+=" 0 as d812, 0 as d816, 0 as d818, 0 as d912, 0 as d916,0 as d918,";
			sql+=" 0 as d1012, 0 as d1016, 0 as d1018, 0 as d1112, 0 as d1116,0 as d1118,";
			sql+=" 0 as d802_, 0 as d806_, 0 as d808_, 0 as d902_, 0 as d906_,0 as d908_,";
			sql+=" 0 as d1002_, 0 as d1006_, 0 as d1008_, 0 as d1102_, 0 as d1106_,0 as d1108_,";

			sql+=" 0 as d301, 0 as d311, 0 as d301_,";
			sql+=" 0 as d401, 0 as d411, 0 as d401_,";
			sql+=" 0 as d501, 0 as d511, 0 as d501_,";
			sql+=" 0 as d601, 0 as d611, 0 as d601_,";
			sql+=" 0 as d801, 0 as d811, 0 as d801_,";
			sql+=" 0 as d901, 0 as d911, 0 as d901_,";
			sql+=" 0 as d1001, 0 as d1011, 0 as d1001_,";
			sql+=" 0 as d1101, 0 as d1111, 0 as d1101_,";

			sql+=" 0 as d303, 0 as d307, 0 as d309, 0 as d403, 0 as d407,0 as d409,";
			sql+=" 0 as d503, 0 as d507, 0 as d509, 0 as d603, 0 as d607,0 as d609,";
			sql+=" 0 as d313, 0 as d317, 0 as d319, 0 as d413, 0 as d417,0 as d419,";
			sql+=" 0 as d513, 0 as d517, 0 as d519, 0 as d613, 0 as d617,0 as d619,";
			sql+=" 0 as d303_, 0 as d307_, 0 as d309_, 0 as d403_, 0 as d407_,0 as d409_,";
			sql+=" 0 as d503_, 0 as d507_, 0 as d509_, 0 as d603_, 0 as d607_,0 as d609_,";		
			sql+=" 0 as d803, 0 as d807, 0 as d809, 0 as d903, 0 as d907,0 as d909,";
			sql+=" 0 as d1003, 0 as d1007, 0 as d1009, 0 as d1103, 0 as d1107,0 as d1109,";
			sql+=" 0 as d813, 0 as d817, 0 as d819, 0 as d913, 0 as d917,0 as d919,";
			sql+=" 0 as d1013, 0 as d1017, 0 as d1019, 0 as d1113, 0 as d1117,0 as d1119,";
			sql+=" 0 as d803_, 0 as d807_, 0 as d809_, 0 as d903_, 0 as d907_,0 as d909_,";
			sql+=" 0 as d1003_, 0 as d1007_, 0 as d1009_, 0 as d1103_, 0 as d1107_,0 as d1109_,";	

			sql+=" '0' as phanloai";
			sql+=" from "+a.user+".a_ct"+s_yy+" ct inner join "+a.user+".a_ctct"+s_yy+" ctct on ct.id=ctct.idct";
			sql+=" inner join "+a.user+".a_dmlk lk on ctct.lk=lk.id";
			sql+=" inner join "+a.user+".a_dmtk tkno on ct.tknoa=tkno.id";
			sql+=" inner join "+a.user+".a_dmtk tkco on ct.tkcoa=tkco.id";
			sql+=" inner join "+a.user+".a_dmng ng on (substr(trim(tkno.stk),6,length(trim(tkno.stk))) =ng.mang or ";
			sql+=" substr(trim(tkno.stk),7,length(trim(tkno.stk)))=ng.mang or";
			sql+=" substr(trim(tkco.stk),6,length(trim(tkco.stk))) =ng.mang or ";
			sql+=" substr(trim(tkco.stk),7,length(trim(tkco.stk)))=ng.mang)";
			sql+=" left join "+a.user+".a_nghiepvu nv on ct.nghiepvu=nv.id";
			sql+=" where (tkno.stk like '461%' or tkno.stk like '462' or tkno.stk like '661' or tkno.stk like '662%' ";
			sql+=" or tkco.stk like '461%' or tkco.stk like '462' or tkco.stk like '661' or tkco.stk like '662%')";
			if(s_IDNguon!="")sql+=" and ng.id="+s_IDNguon+"";
			if(s_IDlk!="")sql+=" and ctct.lk=" + s_IDlk+"";

			if (s_mm !="" || s_mm1!="")
				sql += " AND ct.thanggs BETWEEN "+ s_mm + " AND " + s_mm1;		
			if(s_IDMuc!="")sql+= " and ch.mtm like '" + s_IDMuc+"%'";
			if(s_IDChuong!="")sql+=" and ct.chuong="+s_IDChuong;
			if(s_IDHoatDong!="")sql+=" and ct.hoatdong="+s_IDHoatDong;			
			if(s_IDNhombc!="")sql+=" and ct.idbc="+s_IDNhombc;
			return sql;
		}
		public DataSet ds_tc_fsmKPI(LibKetoan.AccessData a,string s_IDlk,string s_mm, string s_mm1, string s_yy, string s_yyyy, string s_IDChuong,  string s_IDHoatDong, string s_IDMuc, string s_IDNhombc, string s_IDNguon)
		{
			//tinh fat sinh
			sql=tc_fsmKPI(a,s_IDlk,s_mm,s_mm1,s_yy,s_yyyy,s_IDChuong,s_IDHoatDong,s_IDMuc,s_IDNhombc,s_IDNguon);
			//duyet toan danh sach, do du lieu vao cot thich hop
			ds_Data=a.get_data(sql);
			if(ds_Data!=null && ds_Data.Tables[0].Rows.Count>0)
			{
				int i_countfs=ds_Data.Tables[0].Rows.Count-1;
				string s_mang="",s_tkno="",s_tkco="",s_ngvu="";
				decimal d_no=0,d_co=0;
				//khai bao bien hoat dong thuong xuyen
				decimal d_302=0,d_302no=0,d_302co=0,d_306=0,d_306no=0,d_306co=0,d_308=0;
				decimal d_402=0,d_402no=0,d_402co=0,d_406=0,d_406no=0,d_406co=0,d_408=0;
				decimal d_502=0,d_502no=0,d_502co=0,d_506=0,d_506no=0,d_506co=0,d_508=0;
				decimal d_602=0,d_602no=0,d_602co=0,d_606=0,d_606no=0,d_606co=0,d_608=0;

				//khai bao bien du an 
				decimal d_302_=0,d_302no_=0,d_302co_=0,d_306_=0,d_306no_=0,d_306co_=0,d_308_=0;
				decimal d_402_=0,d_402no_=0,d_402co_=0,d_406_=0,d_406no_=0,d_406co_=0,d_408_=0;
				decimal d_502_=0,d_502no_=0,d_502co_=0,d_506_=0,d_506no_=0,d_506co_=0,d_508_=0;
				decimal d_602_=0,d_602no_=0,d_602co_=0,d_606_=0,d_606no_=0,d_606co_=0,d_608_=0;

				//khai bao bien hoat dong khong thuong xuyen
				decimal d_312=0,d_312no=0,d_312co=0,d_316=0,d_316no=0,d_316co=0,d_318=0;
				decimal d_412=0,d_412no=0,d_412co=0,d_416=0,d_416no=0,d_416co=0,d_418=0;
				decimal d_512=0,d_512no=0,d_512co=0,d_516=0,d_516no=0,d_516co=0,d_518=0;
				decimal d_612=0,d_612no=0,d_612co=0,d_616=0,d_616no=0,d_616co=0,d_618=0;
				
				for(int i=0;i<=i_countfs;i++)
				{
					//khoi tao lai gia tri bang 0
						//hoat dong thuong xuyen
					d_302=0;d_302no=0;d_302co=0;d_306=0;d_306no=0;d_306co=0;d_308=0;
					d_402=0;d_402no=0;d_402co=0;d_406=0;d_406no=0;d_406co=0;d_408=0;
					d_502=0;d_502no=0;d_502co=0;d_506=0;d_506no=0;d_506co=0;d_508=0;
					d_602=0;d_602no=0;d_602co=0;d_606=0;d_606no=0;d_606co=0;d_608=0;
					
						//du an 
					d_302_=0;d_302no_=0;d_302co_=0;d_306_=0;d_306no_=0;d_306co_=0;d_308_=0;
					d_402_=0;d_402no_=0;d_402co_=0;d_406_=0;d_406no_=0;d_406co_=0;d_408_=0;
					d_502_=0;d_502no_=0;d_502co_=0;d_506_=0;d_506no_=0;d_506co_=0;d_508_=0;
					d_602_=0;d_602no_=0;d_602co_=0;d_606_=0;d_606no_=0;d_606co_=0;d_608_=0;

						//hoat dong khong thuong xuyen
					d_312=0;d_312no=0;d_312co=0;d_316=0;d_316no=0;d_316co=0;d_318=0;
					d_412=0;d_412no=0;d_412co=0;d_416=0;d_416no=0;d_416co=0;d_418=0;
					d_512=0;d_512no=0;d_512co=0;d_516=0;d_516no=0;d_516co=0;d_518=0;
					d_612=0;d_612no=0;d_612co=0;d_616=0;d_616no=0;d_616co=0;d_618=0;
						

					//khoi tao gia tri cho cac bien
					s_ngvu=ds_Data.Tables[0].Rows[i]["idnghiepvu"].ToString();
					s_mang=ds_Data.Tables[0].Rows[i]["mang"].ToString();
					s_tkno=ds_Data.Tables[0].Rows[i]["tkno"].ToString();
					s_tkco=ds_Data.Tables[0].Rows[i]["tkco"].ToString();
					d_no=Convert.ToDecimal(ds_Data.Tables[0].Rows[i]["no"].ToString());
					d_co=Convert.ToDecimal(ds_Data.Tables[0].Rows[i]["co"].ToString());

					//kiem tra dk, do so lieu
					if(s_mang.Trim().Substring(0,2)=="01" || s_mang.Trim().Substring(0,2)=="02")
					{
						if(s_tkno.Trim()!="" || s_tkco.Trim()!="")
						{
							//hoat dong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_308+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66121"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_306no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66111") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66121")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_306co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46111") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_302co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_302no+=d_no;
							d_302=d_302co-d_302no;
							d_306=d_306no-d_306co;							

							//hoat dong khong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_318+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66122"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_316no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66112") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66122")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_316co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46112") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_312co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_312no+=d_no;
							d_312=d_312co-d_312no;
							d_316=d_316no-d_316co;

							//du an 
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && (s_ngvu=="8" || s_ngvu=="7"))
								d_308_+=d_no;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
								d_306no_+=d_no;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
								d_306co_+=d_co;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_302co_+=d_co;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_302no_+=d_no;
							d_302_=d_302co_-d_302no_;
							d_306_=d_306no_-d_306co_;							
						}
					}
					else
						if(s_mang.Trim().Substring(0,2)=="04")
					{
						if(s_tkno.Trim()!="" || s_tkco.Trim()!="")
						{
							//hoat dong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_408+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66121"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_406no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66111") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66121")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_406co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46111") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_402co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_402no+=d_no;
							d_402=d_402co-d_402no;
							d_406=d_406no-d_406co;

							//hoat dong khong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_418+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66122"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_416no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66112") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66122")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_416co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46112") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_412co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_412no+=d_no;
							d_412=d_412co-d_412no;
							d_416=d_416no-d_416co;

							//du an
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462"&& (s_ngvu=="8" || s_ngvu=="7"))
								d_408_+=d_no;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662"&& s_ngvu!="8"&&s_ngvu!="7")	
								d_406no_+=d_no;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
								d_406co_+=d_co;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_402co_+=d_co;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_402no_+=d_no;
							d_402_=d_402co_-d_402no_;
							d_406_=d_406no_-d_406co_;							
						}
					}
					else
						if(s_mang.Trim().Substring(0,2)=="03")
					{
						if(s_tkno.Trim()!="" || s_tkco.Trim()!="")
						{
							//hoat dong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_508+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66121"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_506no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66111") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66121")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_506co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46111") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_502co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_502no+=d_no;
							d_502=d_502co-d_502no;
							d_506=d_506no-d_506co;

							//hoat dong khong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_518+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66122"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_516no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66112") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66122")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_516co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46112") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_512co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_512no+=d_no;
							d_512=d_512co-d_512no;
							d_516=d_516no-d_516co;

							//du an
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462"&& (s_ngvu=="8" || s_ngvu=="7"))
								d_508_+=d_no;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662"&& s_ngvu!="8"&&s_ngvu!="7")	
								d_506no_+=d_no;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
								d_506co_+=d_co;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_502co_+=d_co;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_502no_+=d_no;
							d_502_=d_502co_-d_502no_;
							d_506_=d_506no_-d_506co_;							
						}
					}
					else 
					{
						if(s_tkno.Trim()!="" || s_tkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_608+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66121"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_606no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66111") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66121")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_606co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46111") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_602co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_602no+=d_no;
							d_602=d_602co-d_602no;
							d_606=d_606no-d_606co;

							//hoat dong khong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_618+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66122"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_616no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66112") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66122")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_616co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46112") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_612co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_612no+=d_no;
							d_612=d_612co-d_612no;
							d_616=d_616no-d_616co;

							//du an
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462"&& (s_ngvu=="8" || s_ngvu=="7"))
								d_608_+=d_no;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662"&& s_ngvu!="8"&&s_ngvu!="7")	
								d_606no_+=d_no;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
								d_606co_+=d_co;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_602co_+=d_co;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_602no_+=d_no;
							d_602_=d_602co_-d_602no_;
							d_606_=d_606no_-d_606co_;
						}
					}
					if(((s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462")|| (s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662"))
						|| ((s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462")|| (s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662")))
						ds_Data.Tables[0].Rows[i]["phanloai"]="II";
					else
						if(((s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="461")|| (s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="661"))
						|| ((s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="461")|| (s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="661")))
						ds_Data.Tables[0].Rows[i]["phanloai"]="I";
					//hoat dong
					ds_Data.Tables[0].Rows[i]["d302"]=d_302;
					ds_Data.Tables[0].Rows[i]["d306"]=d_306;
					ds_Data.Tables[0].Rows[i]["d308"]=d_308;

					ds_Data.Tables[0].Rows[i]["d312"]=d_312;
					ds_Data.Tables[0].Rows[i]["d316"]=d_316;
					ds_Data.Tables[0].Rows[i]["d318"]=d_318;

					ds_Data.Tables[0].Rows[i]["d402"]=d_402;
					ds_Data.Tables[0].Rows[i]["d406"]=d_406;
					ds_Data.Tables[0].Rows[i]["d408"]=d_408;

					ds_Data.Tables[0].Rows[i]["d412"]=d_412;
					ds_Data.Tables[0].Rows[i]["d416"]=d_416;
					ds_Data.Tables[0].Rows[i]["d418"]=d_418;

					ds_Data.Tables[0].Rows[i]["d502"]=d_502;
					ds_Data.Tables[0].Rows[i]["d506"]=d_506;
					ds_Data.Tables[0].Rows[i]["d508"]=d_508;

					ds_Data.Tables[0].Rows[i]["d512"]=d_512;
					ds_Data.Tables[0].Rows[i]["d516"]=d_516;
					ds_Data.Tables[0].Rows[i]["d518"]=d_518;

					ds_Data.Tables[0].Rows[i]["d602"]=d_602;
					ds_Data.Tables[0].Rows[i]["d606"]=d_606;
					ds_Data.Tables[0].Rows[i]["d608"]=d_608;

					ds_Data.Tables[0].Rows[i]["d612"]=d_612;
					ds_Data.Tables[0].Rows[i]["d616"]=d_616;
					ds_Data.Tables[0].Rows[i]["d618"]=d_618;

					//du an
					ds_Data.Tables[0].Rows[i]["d302_"]=d_302_;
					ds_Data.Tables[0].Rows[i]["d306_"]=d_306_;
					ds_Data.Tables[0].Rows[i]["d308_"]=d_308_;					

					ds_Data.Tables[0].Rows[i]["d402_"]=d_402_;
					ds_Data.Tables[0].Rows[i]["d406_"]=d_406_;
					ds_Data.Tables[0].Rows[i]["d408_"]=d_408_;

					ds_Data.Tables[0].Rows[i]["d502_"]=d_502_;
					ds_Data.Tables[0].Rows[i]["d506_"]=d_506_;
					ds_Data.Tables[0].Rows[i]["d508_"]=d_508_;

					ds_Data.Tables[0].Rows[i]["d602_"]=d_602_;
					ds_Data.Tables[0].Rows[i]["d606_"]=d_606_;
					ds_Data.Tables[0].Rows[i]["d608_"]=d_608_;
				}
			}	
			//tinh so du dau ky
			try
			{
				ds_Data2=a.get_SdDauKy_mKPI(s_yy,s_mm,s_IDMuc,s_IDlk,s_IDChuong,s_IDHoatDong,s_IDNhombc,s_IDNguon);
				if(ds_Data2!=null)
					ds_Data.Merge(ds_Data2);
				ds_Data.AcceptChanges();
			}catch{flag_dsnull=true;};
			//tinh luyke
			sql1=tc_fsmKPI(a,s_IDlk,"01",s_mm1,s_yy,s_yyyy,s_IDChuong,s_IDHoatDong,s_IDMuc,s_IDNhombc,s_IDNguon);
			ds_Data3=a.get_data(sql1);
			if(ds_Data3!=null && ds_Data3.Tables[0].Rows.Count>0)
			{				
				int i_countlk=ds_Data3.Tables[0].Rows.Count-1;
				string s_lkmang="",s_lktkno="",s_lktkco="",s_lkngvu="";
				decimal d_lkno=0,d_lkco=0;
				//khai bao bien hoat dong thuong xuyen
				decimal d_303=0,d_303no=0,d_303co=0,d_307=0,d_307no=0,d_307co=0,d_309=0;
				decimal d_403=0,d_403no=0,d_403co=0,d_407=0,d_407no=0,d_407co=0,d_409=0;
				decimal d_503=0,d_503no=0,d_503co=0,d_507=0,d_507no=0,d_507co=0,d_509=0;
				decimal d_603=0,d_603no=0,d_603co=0,d_607=0,d_607no=0,d_607co=0,d_609=0;

				//khai bao bien du an
				decimal d_303_=0,d_303no_=0,d_303co_=0,d_307_=0,d_307no_=0,d_307co_=0,d_309_=0;
				decimal d_403_=0,d_403no_=0,d_403co_=0,d_407_=0,d_407no_=0,d_407co_=0,d_409_=0;
				decimal d_503_=0,d_503no_=0,d_503co_=0,d_507_=0,d_507no_=0,d_507co_=0,d_509_=0;
				decimal d_603_=0,d_603no_=0,d_603co_=0,d_607_=0,d_607no_=0,d_607co_=0,d_609_=0;

				//khai bao bien hoat dong khong thuong xuyen
				decimal d_313=0,d_313no=0,d_313co=0,d_317=0,d_317no=0,d_317co=0,d_319=0;
				decimal d_413=0,d_413no=0,d_413co=0,d_417=0,d_417no=0,d_417co=0,d_419=0;
				decimal d_513=0,d_513no=0,d_513co=0,d_517=0,d_517no=0,d_517co=0,d_519=0;
				decimal d_613=0,d_613no=0,d_613co=0,d_617=0,d_617no=0,d_617co=0,d_619=0;
				
				for(int j=0;j<=i_countlk;j++)
				{
					//khoi tao lai gia tri bang 0
					//hoat dong thuong xuyen
					d_303=0;d_303no=0;d_303co=0;d_307=0;d_307no=0;d_307co=0;d_309=0;
					d_403=0;d_403no=0;d_403co=0;d_407=0;d_407no=0;d_407co=0;d_409=0;
					d_503=0;d_503no=0;d_503co=0;d_507=0;d_507no=0;d_507co=0;d_509=0;
					d_603=0;d_603no=0;d_603co=0;d_607=0;d_607no=0;d_607co=0;d_609=0;
				
					//du an
					d_303_=0;d_303no_=0;d_303co_=0;d_307_=0;d_307no_=0;d_307co_=0;d_309_=0;
					d_403_=0;d_403no_=0;d_403co_=0;d_407_=0;d_407no_=0;d_407co_=0;d_409_=0;
					d_503_=0;d_503no_=0;d_503co_=0;d_507_=0;d_507no_=0;d_507co_=0;d_509_=0;
					d_603_=0;d_603no_=0;d_603co_=0;d_607_=0;d_607no_=0;d_607co_=0;d_609_=0;

					//hoat dong khong thuong xuyen
					d_313=0;d_313no=0;d_313co=0;d_317=0;d_317no=0;d_317co=0;d_319=0;
					d_413=0;d_413no=0;d_413co=0;d_417=0;d_417no=0;d_417co=0;d_419=0;
					d_513=0;d_513no=0;d_513co=0;d_517=0;d_517no=0;d_517co=0;d_519=0;
					d_613=0;d_613no=0;d_613co=0;d_617=0;d_617no=0;d_617co=0;d_619=0;
					
					//khoi tao gia tri cho cac bien
					s_lkngvu=ds_Data3.Tables[0].Rows[j]["idnghiepvu"].ToString();
					s_lkmang=ds_Data3.Tables[0].Rows[j]["mang"].ToString();
					s_lktkno=ds_Data3.Tables[0].Rows[j]["tkno"].ToString();
					s_lktkco=ds_Data3.Tables[0].Rows[j]["tkco"].ToString();
					d_lkno=Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["no"].ToString());
					d_lkco=Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["co"].ToString());

					//kiem tra dk, do so lieu
					if(s_lkmang.Trim().Substring(0,2)=="01" || s_lkmang.Trim().Substring(0,2)=="02")
					{
						if(s_lktkno.Trim()!="" || s_lktkco.Trim()!="")
						{
							//hoat dong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_309+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66121"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_307no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66111") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66121")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_307co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46111") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_303co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_303no+=d_lkno;
							d_303=d_303co-d_303no;
							d_307=d_307no-d_307co;							

							//hoat dong khong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_319+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66122"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_317no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66112") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66122")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_317co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46112") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_313co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_313no+=d_lkno;
							d_313=d_313co-d_313no;
							d_317=d_317no-d_317co;

							//du an
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && (s_lkngvu=="8" || s_lkngvu=="7"))
								d_309_+=d_lkno;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_307no_+=d_lkno;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_307co_+=d_lkco;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_303co_+=d_lkco;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_303no_+=d_lkno;
							d_303_=d_303co_-d_303no_;
							d_307_=d_307no_-d_307co_;
							
						}
					}
					else
						if(s_lkmang.Trim().Substring(0,2)=="04")
					{
						if(s_lktkno.Trim()!="" || s_lktkco.Trim()!="")
						{
							//hoat dong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_409+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66121"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_407no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66111") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66121")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_407co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46111") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_403co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_403no+=d_lkno;
							d_403=d_403co-d_403no;
							d_407=d_407no-d_407co;

							//hoat dong khong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_419+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66122"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_417no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66112") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66122")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_417co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46112") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_413co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_413no+=d_lkno;
							d_413=d_413co-d_413no;
							d_417=d_417no-d_417co;

							//du an 
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462"&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_409_+=d_lkno;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662"&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_407no_+=d_lkno;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_407co_+=d_lkco;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_403co_+=d_lkco;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_403no_+=d_lkno;
							d_403_=d_403co_-d_403no_;
							d_407_=d_407no_-d_407co_;
						}
					}
					else
						if(s_lkmang.Trim().Substring(0,2)=="03")
					{
						if(s_lktkno.Trim()!="" || s_lktkco.Trim()!="")
						{
							//hoat dong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_509+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66121"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_507no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66111") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66121")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_507co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46111") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_503co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_503no+=d_lkno;
							d_503=d_503co-d_503no;
							d_507=d_507no-d_507co;

							//hoat dong khong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_519+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66122"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_517no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66112") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66122")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_517co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46112") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_513co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_513no+=d_lkno;
							d_513=d_513co-d_513no;
							d_517=d_517no-d_517co;

							//du an
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462"&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_509_+=d_lkno;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662"&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_507no_+=d_lkno;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_507co_+=d_lkco;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_503co_+=d_lkco;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_503no_+=d_lkno;
							d_503_=d_503co_-d_503no_;
							d_507_=d_507no_-d_507co_;
						}
					}
					else 
					{
						if(s_lktkno.Trim()!="" || s_lktkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_609+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66121"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_607no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66111") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66121")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_607co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46111") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_603co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_603no+=d_lkno;
							d_603=d_603co-d_603no;
							d_607=d_607no-d_607co;

							//hoat dong khong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_619+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66122"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_617no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66112") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66122")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_617co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46112") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_613co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_613no+=d_lkno;
							d_613=d_613co-d_613no;
							d_617=d_617no-d_617co;

							//du an
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462"&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_609_+=d_lkno;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662"&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_607no_+=d_lkno;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_607co_+=d_lkco;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_603co_+=d_lkco;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_603no_+=d_lkno;
							d_603_=d_603co_-d_603no_;
							d_607_=d_607no_-d_607co_;
						}
					}
					if(((s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462")|| (s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662"))
						|| ((s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462")|| (s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662")))
						ds_Data3.Tables[0].Rows[j]["phanloai"]="II";
					else
						if(((s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="461")|| (s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="661"))
						|| ((s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="461")|| (s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="661")))
						ds_Data3.Tables[0].Rows[j]["phanloai"]="I";
					//hoat dong
					ds_Data3.Tables[0].Rows[j]["d303"]=d_303;
					ds_Data3.Tables[0].Rows[j]["d307"]=d_307;
					ds_Data3.Tables[0].Rows[j]["d309"]=d_309;

					ds_Data3.Tables[0].Rows[j]["d313"]=d_313;
					ds_Data3.Tables[0].Rows[j]["d317"]=d_317;
					ds_Data3.Tables[0].Rows[j]["d319"]=d_319;

					ds_Data3.Tables[0].Rows[j]["d403"]=d_403;
					ds_Data3.Tables[0].Rows[j]["d407"]=d_407;
					ds_Data3.Tables[0].Rows[j]["d409"]=d_409;

					ds_Data3.Tables[0].Rows[j]["d413"]=d_413;
					ds_Data3.Tables[0].Rows[j]["d417"]=d_417;
					ds_Data3.Tables[0].Rows[j]["d419"]=d_419;

					ds_Data3.Tables[0].Rows[j]["d503"]=d_503;
					ds_Data3.Tables[0].Rows[j]["d507"]=d_507;
					ds_Data3.Tables[0].Rows[j]["d509"]=d_509;

					ds_Data3.Tables[0].Rows[j]["d513"]=d_513;
					ds_Data3.Tables[0].Rows[j]["d517"]=d_517;
					ds_Data3.Tables[0].Rows[j]["d519"]=d_519;

					ds_Data3.Tables[0].Rows[j]["d603"]=d_603;
					ds_Data3.Tables[0].Rows[j]["d607"]=d_607;
					ds_Data3.Tables[0].Rows[j]["d609"]=d_609;

					ds_Data3.Tables[0].Rows[j]["d613"]=d_613;
					ds_Data3.Tables[0].Rows[j]["d617"]=d_617;
					ds_Data3.Tables[0].Rows[j]["d619"]=d_619;

					//du an
					ds_Data3.Tables[0].Rows[j]["d303_"]=d_303_;
					ds_Data3.Tables[0].Rows[j]["d307_"]=d_307_;
					ds_Data3.Tables[0].Rows[j]["d309_"]=d_309_;

					ds_Data3.Tables[0].Rows[j]["d403_"]=d_403_;
					ds_Data3.Tables[0].Rows[j]["d407_"]=d_407_;
					ds_Data3.Tables[0].Rows[j]["d409_"]=d_409_;

					ds_Data3.Tables[0].Rows[j]["d503_"]=d_503_;
					ds_Data3.Tables[0].Rows[j]["d507_"]=d_507_;
					ds_Data3.Tables[0].Rows[j]["d509_"]=d_509_;

					ds_Data3.Tables[0].Rows[j]["d603_"]=d_603_;
					ds_Data3.Tables[0].Rows[j]["d607_"]=d_607_;
					ds_Data3.Tables[0].Rows[j]["d609_"]=d_609_;
				}
			}
			
			if(ds_Data3!=null)
				ds_Data.Merge(ds_Data3);
			ds_Data.AcceptChanges();
			try
			{
				if(flag_dsnull)return null;
				else 
					ds_Data.WriteXml("..\\xml\\KT_mKPI.xml",XmlWriteMode.WriteSchema);
			}
			catch{}
				return ds_Data;
			}		
		private string fsdutoan_nskhobac(LibKetoan.AccessData a,string s_IDlk,string s_IDtk,string s_mm, string s_mm1, string s_yy, string s_yyyy, string s_IDChuong,  string s_IDHoatDong, string s_IDNhommuc, string s_IDNguon,string s_IDNhombc)
		{
			//lay so lieu trong chung tu
			sql="";
			sql="select tkco.stk as stk,lk.lk as lk, substr(trim(lk.lk),0,3) as loai, ";
			sql+=" substr(trim(lk.lk),5,3) as khoan, nh.nhom as nhommuc,";			
			sql+=" case when length(trim(ch.mtm))>3 then substr(trim(ch.mtm),0,4)else '' end as muc, ";
			sql+=" case when length(trim(ch.mtm))>8 then substr(trim(ch.mtm),6,4)else '' end as tm, ";
			sql+=" 0 as ntruoc, 0 as dgiao,0 as bsung,ct.nghiepvu as nvu,";
			//sql1+=" tkco.stk as tkco,";
			sql+=" case when tkco.stk like '008%' then ctct.stien else 0 end as co,";
			sql+=" 0 as fsdt_darut, 0 as lkdt_darut,0 as fsnopkpdt, 0 as lknopkpdt";
			sql+=" from "+a.user+".a_ctct"+s_yy+" ctct inner join "+a.user+".a_ct"+s_yy+" ct on ct.id=ctct.idct ";
			sql+=" left join "+a.user+".a_dmtk tkco on ctct.tkcoa=tkco.id ";
			sql+=" inner join "+a.user+".a_dmlk lk on lk.id=ctct.lk ";
			sql+=" inner join "+a.user+".a_dmng ng on substr(trim(tkco.stk),6,length(trim(tkco.stk))) =ng.mang ";
			sql+=" left join "+a.user+".a_dmch ch on (ctct.mtmno=ch.id or ctct.mtmco=ch.id) ";
			sql+=" left join "+a.user+".a_dmnhom nh on ch.nhmuc=nh.id";
			sql+=" where tkco.stk like '008%'";
			if(s_IDNguon!="")sql+=" and ng.id="+s_IDNguon+"";
			if(s_IDlk!="")sql+=" and ctct.lk=" + s_IDlk+"";
			if (s_mm !="" || s_mm1!="")
				sql += " AND ct.thanggs BETWEEN "+ s_mm + " AND " + s_mm1;		
			//if(s_IDMuc!="")sql+= " and ch.muc like '" + s_IDMuc+"%'";			
			if(s_IDChuong!="")sql+=" and ct.chuong="+s_IDChuong;
			if(s_IDHoatDong!="")sql+=" and ct.hoatdong="+s_IDHoatDong;			
			if(s_IDNhommuc!="") sql+=" AND ch.nhmuc="+s_IDNhommuc;
			if(s_IDNhombc!="")sql+=" and ct.idbc="+s_IDNhombc;	
			return sql;
		}
		public DataSet dutoan_nskhobac(LibKetoan.AccessData a,string s_IDlk,string s_IDtk,string s_mm, string s_mm1, string s_yy, string s_yyyy, string s_IDChuong,  string s_IDHoatDong, string s_IDNhommuc, string s_IDNguon,string s_IDNhombc)
		{
			//lay so lieu trong a_dutoanns
			sql="select tk.stk, lk.lk,ntruoc , dgiao, bsung, substr(trim(lk.lk),0,3) as loai,";
			sql+=" substr(trim(lk.lk),5,3) as khoan, nh.nhom as nhommuc,";			
			sql+=" case when length(trim(ch.mtm))>3 then substr(trim(ch.mtm),0,4)else '' end as muc, ";
			sql+=" case when length(trim(ch.mtm))>8 then substr(trim(ch.mtm),6,4)else '' end as tm, ";
			sql+=" 0 as fsdt_darut, 0 as lkdt_darut,0 as fsnopkpdt, 0 as lknopkpdt, 0 as co";
			sql+=" from "+a.user+".a_dutoanns"+s_yy+" dt inner join "+a.user+".a_dmtk tk on dt.stk=tk.id";
			sql+=" left join "+a.user+".a_dmlk lk on dt.lk=lk.id ";
			sql+=" left join "+a.user+".a_dmng ng on substr(trim(dt.stk),6,length(trim(dt.stk)))=ng.mang ";
			sql+=" left join "+a.user+".a_dmch ch on dt.muc=ch.id ";
			sql+=" left join "+a.user+".a_dmnhom nh on dt.nhmuc=nh.id ";
			sql+=" where tk.stk like '008%'";
			sql+=" and dt.stk in("+s_IDtk+")";
			if(s_IDNguon!="")sql+=" and dt.kp="+s_IDNguon+"";
			if(s_IDlk!="")sql+=" and dt.lk=" + s_IDlk+"";
			if (s_mm !="" || s_mm1!="")
				sql += " AND dt.thanggs BETWEEN "+ s_mm + " AND " + s_mm1;		
			//if(s_IDMuc!="")sql+= " and dt.muc like '" + s_IDMuc+"%'";
			if(s_IDChuong!="")sql+=" and dt.chuong="+s_IDChuong;
			if(s_IDHoatDong!="")sql+=" and dt.hoatdong="+s_IDHoatDong;			
			if (s_IDNhommuc!="") sql+=" AND dt.nhmuc="+s_IDNhommuc;	
			try
			{
				ds_Data=a.get_data(sql);
			}
			catch{flag_dsnull=true;};
			//lay chung tu fat sinh
			sql1="";
			sql1=fsdutoan_nskhobac(a,s_IDlk,s_IDtk,s_mm,s_mm1,s_yy,s_yyyy,s_IDChuong,s_IDHoatDong,s_IDNhommuc,s_IDNguon,s_IDNhombc);
			try
			{
				ds_Data2=a.get_data(sql1);
				if(ds_Data2!=null)// && ds_Data2.Tables[0].Rows.Count>0)
				{
					//duyet data, lay thong tin do vao cot thich hop
					int count_ds2=ds_Data2.Tables[0].Rows.Count;
					string s_ngvu="";
					decimal d_fsco=0,d_fsdt_rut=0,d_fsnopkp=0;
					for(int i=0;i<=count_ds2-1;i++)
					{
						d_fsdt_rut=0;d_fsnopkp=0;
						s_ngvu=ds_Data2.Tables[0].Rows[i]["nvu"].ToString();						
						d_fsco=Convert.ToDecimal(ds_Data2.Tables[0].Rows[i]["co"].ToString());
						if(s_ngvu!="" && (s_ngvu!="7" && s_ngvu!="10"))
							d_fsdt_rut+=d_fsco;
						else if(s_ngvu!="" && (s_ngvu=="7"||s_ngvu=="10"))
							d_fsnopkp+=-d_fsco;						
						ds_Data2.Tables[0].Rows[i]["fsdt_darut"]=d_fsdt_rut;
						ds_Data2.Tables[0].Rows[i]["fsnopkpdt"]=d_fsnopkp;
					}
					ds_Data.Merge(ds_Data2);
					ds_Data.AcceptChanges();
				}
				//lay luy ke
				sql1="";
				sql1=fsdutoan_nskhobac(a,s_IDlk,s_IDtk,"01",s_mm1,s_yy,s_yyyy,s_IDChuong,s_IDHoatDong,s_IDNhommuc,s_IDNguon,s_IDNhombc);
				ds_Data3=a.get_data(sql1);
				if(ds_Data3!=null)// && ds_Data3.Tables[0].Rows.Count>0)
				{
					//duyet data, lay thong tin do vao cot thich hop
					int count_ds3=ds_Data3.Tables[0].Rows.Count;
					string s_lkngvu="";
					decimal d_lkco=0,d_lkdt_rut=0,d_lknopkp=0;
					for(int j=0;j<=count_ds3-1;j++)
					{
						d_lkdt_rut=0;d_lknopkp=0;
						s_lkngvu=ds_Data3.Tables[0].Rows[j]["nvu"].ToString();						
						d_lkco=Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["co"].ToString());
						if(s_lkngvu!="" && (s_lkngvu!="7"&&s_lkngvu!="10"))
							d_lkdt_rut+=d_lkco;
						else if(s_lkngvu!="" && (s_lkngvu=="7"||s_lkngvu=="10"))
							d_lknopkp+=-d_lkco;						
						ds_Data3.Tables[0].Rows[j]["lkdt_darut"]=d_lkdt_rut;
						ds_Data3.Tables[0].Rows[j]["lknopkpdt"]=d_lknopkp;
					}
					ds_Data.Merge(ds_Data3);
					ds_Data.AcceptChanges();
				}				
				if(ds_Data!=null && ds_Data.Tables[0].Rows.Count>0)
					ds_Data.WriteXml("..\\xml\\KT_dutoan_nskhobac.xml",XmlWriteMode.WriteSchema);
				else
					flag_dsnull=true;
			}			
			catch{throw;};
			if(flag_dsnull)return null;
			else return ds_Data;
		}
		private string fsTamungKP_KhoBac(LibKetoan.AccessData a,string s_IDlk,string s_IDtk,string s_mm, string s_mm1, string s_yy, string s_yyyy, string s_IDChuong,  string s_IDHoatDong, string s_IDNhommuc, string s_IDNguon,string s_IDNhombc)
		{
			sql="";
			sql=" select t2.tenmuc,t1.* from (";
			sql+="select distinct ctct.thangqt, to_char(ct.ngaygs,'dd/mm/yyyy') as ngaygs,to_char(ct.ngayg,'dd/mm/yyyy') as ngayg,";
			sql+=" ct.soctg as sohieu, ct.noidung as diengiai,";
			sql+=" ch.ttk as chitieu,";
			sql+=" lk.lk as lk, substr(trim(lk.lk),0,3) as loai,";
			sql+=" substr(trim(lk.lk),5,3) as khoan, nh.nhom as nhommuc,";
			sql+=" case when length(trim(ch.mtm))>3 then substr(trim(ch.mtm),0,4)else '' end as muc, ";	
			sql+=" case when length(trim(ch.mtm))>8 then substr(trim(ch.mtm),6,4)else '' end as tm, ";
			sql+=" sum(case when ctct.tknoa in("+s_IDtk+") then ctct.stien else 0 end)as no,";
			sql+=" sum(case when ctct.tkcoa in("+s_IDtk+") then ctct.stien else 0 end) as co,";
			sql+=" tkno.stk as tkno, tkco.stk as tkco,nv.id as nvu,nv.ten as tenngvu,ng.ten as tennguon,";
			sql+=" 0 as cot1,0 as cot2,0 as cot3,";
			sql+=" 0 as sdcot1,0 as sdcot2,0 as sdcot3,";
			sql+=" 0 as lkcot1,0 as lkcot2,0 as lkcot3";
			sql+=" from "+a.user+".a_ct09 ct inner join "+a.user+".a_ctct09 ctct on ct.id=ctct.idct";
			sql+=" inner join "+a.user+".a_dmtk tkno on tkno.id=ctct.tknoa";
			sql+=" inner join "+a.user+".a_dmtk tkco on tkco.id=ctct.tkcoa";
			sql+=" inner join a_dmlk lk on lk.id=ctct.lk";
			sql+=" inner join "+a.user+".a_nghiepvu nv on nv.id=ct.nghiepvu";
			sql+=" inner join "+a.user+".a_dmch ch on (ch.id=ctct.mtmno or ch.id=ctct.mtmco)";
			sql+=" inner join a_dmnhom nh on nh.id=ch.nhmuc";
			sql+=" inner join "+a.user+".a_dmng ng on (substr(trim(tkno.stk),7,length(trim(tkno.stk)))=ng.mang or substr(trim(tkco.stk),7,length(trim(tkco.stk)))=ng.mang )";
			sql+=" where (ctct.tkcoa in ("+s_IDtk+") or ctct.tknoa in ("+s_IDtk+"))";
			if(s_IDNguon!="")sql+=" and ng.id="+s_IDNguon+"";
			if(s_IDlk!="")sql+=" and ctct.lk=" + s_IDlk+"";
			if (s_mm !="" || s_mm1!="")
				sql += " AND ct.thanggs BETWEEN "+ s_mm + " AND " + s_mm1;		
			if(s_IDNhommuc!="")sql+= " and ch.mtm like '" + s_IDNhommuc+"%'";
			if(s_IDChuong!="")sql+=" and ct.chuong="+s_IDChuong;
			if(s_IDHoatDong!="")sql+=" and ct.hoatdong="+s_IDHoatDong;			
			if(s_IDNhombc!="")sql+=" and ct.idbc="+s_IDNhombc;	
			sql+=" group by ch.mtm, ctct.thangqt,to_char(ct.ngaygs,'dd/mm/yyyy') ,to_char(ct.ngayg,'dd/mm/yyyy') , ct.soctg , ct.noidung ,";
			sql+=" tkno.stk , tkco.stk ,nv.id ,nv.ten,ng.ten,lk.lk,nh.nhom,ch.ttk";
			sql+=" order by ct.soctg";
			sql+=" ) t1 inner join (select ch.mtm as muc,ch.ttk as tenmuc from a_dmch ch) t2 on t1.muc=t2.muc";
			return sql;
		}
		public DataSet TamungKP_KhoBac(LibKetoan.AccessData a,string s_IDlk,string s_IDtk,string s_mm, string s_mm1, string s_yy, string s_yyyy, string s_IDChuong,  string s_IDHoatDong, string s_IDNhommuc, string s_IDNguon,string s_IDNhombc)
		{
			int i_mm1=Convert.ToInt32(s_mm.PadLeft(1));
			int i_mm2=Convert.ToInt32(s_mm1.PadLeft(1));
			//tinh so lieu fat sinh
			sql=fsTamungKP_KhoBac(a,s_IDlk,s_IDtk,s_mm,s_mm1,s_yy,s_yyyy,s_IDChuong,s_IDHoatDong,s_IDNhommuc,s_IDNguon,s_IDNhombc);			
			ds_Data=a.get_data(sql);
			try
			{
				if(ds_Data!=null && ds_Data.Tables[0].Rows.Count>0)
				{
					//duyet dataset, do du lieu vao cac cot thich hop
					int i_countds=ds_Data.Tables[0].Rows.Count,i_thangqt=0;
					string s_tkno="",s_tkco="",s_nvu="",s_thangqt=""; //,s_tkno_4612="",s_tkco_4612="",s_tkno_6612="",nvu="";
					decimal cot1=0,cot2=0,cot3=0,d_fsno=0,d_fsco=0;
					for(int i=0;i<=i_countds-1;i++)
					{
						//khoi tao gia tri
						cot1=0;cot2=0;cot3=0;
						//khai bao gia tri
						s_tkno=ds_Data.Tables[0].Rows[i]["tkno"].ToString();
						s_tkco=ds_Data.Tables[0].Rows[i]["tkco"].ToString();
						d_fsno=Convert.ToDecimal(ds_Data.Tables[0].Rows[i]["no"].ToString());
						d_fsco=Convert.ToDecimal(ds_Data.Tables[0].Rows[i]["co"].ToString());
						s_thangqt= ds_Data.Tables[0].Rows[i]["thangqt"].ToString();
						if(s_thangqt!="")i_thangqt=Convert.ToInt32(s_thangqt.PadLeft(1));
						s_nvu=ds_Data.Tables[0].Rows[i]["nvu"].ToString();

						if(s_tkno.Trim().Length>3&&s_tkno.Trim().Substring(0,3)=="336")
						{
							if(s_nvu!=""&& s_nvu!="7"&&s_nvu!="8")
								cot2+=d_fsno;
							if(s_nvu!=""&&(s_nvu=="7"||s_nvu=="8"))
								cot3+=d_fsno;							
						}
						else
						if(s_tkco.Trim().Length>3&&s_tkco.Trim().Substring(0,3)=="336")
							cot1+=d_fsco;
						else
						if(s_tkno.Trim().Length>4&&(s_tkno.Trim().Substring(0,4)=="4612" || (s_tkno.Trim().Substring(0,4)=="6612")))
						{
							if(s_tkno.Trim().Length>4&&s_tkno.Trim().Substring(0,4)=="6612")
							{								
								if(i_thangqt!=0&&i_thangqt>=i_mm1 &&i_thangqt<=i_mm2 &&(s_nvu=="2"||s_nvu=="3"))
									cot2+=d_fsno;
							}		
							else if(s_tkno.Trim().Length>4&&s_tkno.Trim().Substring(0,4)=="4612" && (s_nvu==""||s_nvu=="8"))
								cot3+=d_fsno;							
						}
						else 
							if(s_tkco.Trim().Length>4&&s_tkco.Trim().Substring(0,4)=="4612")
								if(s_nvu!="7"&&s_nvu!="8")
									cot1+=d_fsco;
						ds_Data.Tables[0].Rows[i]["cot1"]=cot1;
						ds_Data.Tables[0].Rows[i]["cot2"]=cot2;
						ds_Data.Tables[0].Rows[i]["cot3"]=cot3;
					}				
					
				}				
				if(i_mm1>1)
				{	//tinh so du dau ky
					string s_tu=(i_mm1-1).ToString().PadLeft(2,'0');
					sql1=fsTamungKP_KhoBac(a,s_IDlk,s_IDtk,"01",s_tu,s_yy,s_yyyy,s_IDChuong,s_IDHoatDong,s_IDNhommuc,s_IDNguon,s_IDNhombc);
					ds_Data2=a.get_data(sql1);
					if(ds_Data2!=null && ds_Data2.Tables[0].Rows.Count>0)
					{
						//duyet dataset, do du lieu vao cac cot thich hop
						int i_countsd=ds_Data2.Tables[0].Rows.Count,i_thangqtsd=0;
						string s_sdtkno="",s_sdtkco="",s_sdnvu="",s_thangqtsd=""; //,s_tkno_4612="",s_tkco_4612="",s_tkno_6612="",nvu="";
						decimal sdcot1=0,sdcot2=0,sdcot3=0,d_sdno=0,d_sdco=0;
						for(int j=0;j<=i_countsd-1;j++)
						{
							//khoi tao gia tri
							sdcot1=0;sdcot2=0;sdcot3=0;
							//khai bao gia tri
							s_sdtkno=ds_Data2.Tables[0].Rows[j]["tkno"].ToString();
							s_sdtkco=ds_Data2.Tables[0].Rows[j]["tkco"].ToString();
							d_sdno=Convert.ToDecimal(ds_Data2.Tables[0].Rows[j]["no"].ToString());
							d_sdco=Convert.ToDecimal(ds_Data2.Tables[0].Rows[j]["co"].ToString());
							s_thangqtsd= ds_Data2.Tables[0].Rows[j]["thangqt"].ToString();
							if(s_thangqtsd!="")i_thangqtsd=Convert.ToInt32(s_thangqtsd.PadLeft(1));
							s_sdnvu=ds_Data2.Tables[0].Rows[j]["nvu"].ToString();

							if(s_sdtkno.Trim().Length>3&&s_sdtkno.Trim().Substring(0,3)=="336")
							{
								if(s_sdnvu!=""&& s_sdnvu!="7"&&s_sdnvu!="8")
									sdcot2+=d_sdno;
								if(s_sdnvu!=""&&(s_sdnvu=="7"||s_sdnvu=="8"))
									sdcot3+=d_sdno;							
							}
							else
								if(s_sdtkco.Trim().Length>3&&s_sdtkco.Trim().Substring(0,3)=="336")
								sdcot1+=d_sdco;
							else
								//if(s_tkno.Trim().Length>4&&(s_tkno.Trim().Substring(0,4)=="4612" )
								if(s_sdtkno.Trim().Length>4&&(s_sdtkno.Trim().Substring(0,4)=="4612"|| (s_sdtkno.Trim().Substring(0,4)=="6612")))
							{
								if(s_sdtkno.Trim().Length>4&&s_sdtkno.Trim().Substring(0,4)=="6612")
								{								
									if(i_thangqtsd!=0&&i_thangqtsd>=1 &&i_thangqtsd<=i_mm1-1 &&(s_sdnvu=="2"||s_sdnvu=="3"))
										sdcot2+=d_sdno;
								}		
								else if(s_sdtkno.Trim().Length>4&&s_sdtkno.Trim().Substring(0,4)=="4612" && (s_sdnvu==""||s_sdnvu=="8"))
									sdcot3+=d_sdno;							
							}
							else 
								if(s_sdtkco.Trim().Length>4&&s_sdtkco.Trim().Substring(0,4)=="4612")
								if(s_sdnvu!="7"&&s_sdnvu!="8")
									sdcot1+=d_sdco;
							ds_Data2.Tables[0].Rows[j]["sdcot1"]=sdcot1;
							ds_Data2.Tables[0].Rows[j]["sdcot2"]=sdcot2;
							ds_Data2.Tables[0].Rows[j]["sdcot3"]=sdcot3;
						}
						ds_Data.Merge(ds_Data2);
						ds_Data.AcceptChanges();
					}
				}
				//tinh luy ke	
				sql1="";
				sql1=fsTamungKP_KhoBac(a,s_IDlk,s_IDtk,"01",s_mm1,s_yy,s_yyyy,s_IDChuong,s_IDHoatDong,s_IDNhommuc,s_IDNguon,s_IDNhombc);
				ds_Data3=a.get_data(sql1);
				if(ds_Data3!=null && ds_Data3.Tables[0].Rows.Count>0)
				{
					//duyet dataset, do du lieu vao cac cot thich hop
					int i_countlk=ds_Data3.Tables[0].Rows.Count,i_thangqtlk=0;
					string s_lktkno="",s_lktkco="",s_lknvu="",s_thangqtlk=""; //,s_tkno_4612="",s_tkco_4612="",s_tkno_6612="",nvu="";
					decimal lkcot1=0,lkcot2=0,lkcot3=0,d_lkno=0,d_lkco=0;
					for(int k=0;k<=i_countlk-1;k++)
					{
						//khoi tao gia tri
						lkcot1=0;lkcot2=0;lkcot3=0;
						//khai bao gia tri
						s_lktkno=ds_Data3.Tables[0].Rows[k]["tkno"].ToString();
						s_lktkco=ds_Data3.Tables[0].Rows[k]["tkco"].ToString();
						d_lkno=Convert.ToDecimal(ds_Data3.Tables[0].Rows[k]["no"].ToString());
						d_lkco=Convert.ToDecimal(ds_Data3.Tables[0].Rows[k]["co"].ToString());
						s_thangqtlk= ds_Data3.Tables[0].Rows[k]["thangqt"].ToString();
						if(s_thangqtlk!="")i_thangqtlk=Convert.ToInt32(s_thangqtlk.PadLeft(1));
						s_lknvu=ds_Data3.Tables[0].Rows[k]["nvu"].ToString();

						if(s_lktkno.Trim().Length>3&&s_lktkno.Trim().Substring(0,3)=="336")
						{
							if(s_lknvu!=""&& s_lknvu!="7"&&s_lknvu!="8")
								lkcot2+=d_lkno;
							if(s_lknvu!=""&&(s_lknvu=="7"||s_lknvu=="8"))
								lkcot3+=d_lkno;							
						}
						else
							if(s_lktkco.Trim().Length>3&&s_lktkco.Trim().Substring(0,3)=="336")
							lkcot1+=d_lkco;
						else
							if(s_lktkno.Trim().Length>4&&(s_lktkno.Trim().Substring(0,4)=="4612"|| (s_lktkno.Trim().Substring(0,4)=="6612")))
						{
							if(s_lktkno.Trim().Length>4&&s_lktkno.Trim().Substring(0,4)=="6612")
							{								
								if(i_thangqtlk!=0&&i_thangqtlk>=i_mm1 &&i_thangqtlk<=i_mm2 &&(s_lknvu=="2"||s_lknvu=="3"))
									lkcot2+=d_lkno;
							}		
							else if(s_lktkno.Trim().Length>4&&s_lktkno.Trim().Substring(0,4)=="4612" && (s_lknvu==""||s_lknvu=="8"))
								lkcot3+=d_lkno;							
						}
						else 
							if(s_lktkco.Trim().Length>4&&s_lktkco.Trim().Substring(0,4)=="4612")
							if(s_lknvu!="7"&&s_lknvu!="8")
								lkcot1+=d_lkco;
						ds_Data3.Tables[0].Rows[k]["lkcot1"]=lkcot1;
						ds_Data3.Tables[0].Rows[k]["lkcot2"]=lkcot2;
						ds_Data3.Tables[0].Rows[k]["lkcot3"]=lkcot3;
					}
					ds_Data.Merge(ds_Data3);
					ds_Data.AcceptChanges();
				}
				if(ds_Data!=null && ds_Data.Tables[0].Rows.Count>0)	flag_dsnull=false;			
					ds_Data.WriteXml("..\\xml\\KT_TamungKP_KhoBac.xml",XmlWriteMode.WriteSchema);
			}
			catch{flag_dsnull=true;};
			if(flag_dsnull)return null;
			else return ds_Data;
		}
		
		public DataSet SoTheoDoiGiaoDuToan(AccessData a, string s_IDtk, string s_IDlk,string s_IDChuong, string s_IDHoatdong, string s_IDNguongoc,string s_IDNhomMuc,string s_yy)
		{
			flag_dsnull = false;
			sql = " SELECT sum(case when (ns.q ) = 1 then ((dgiao) ) else 0 end) as dagiao1,";
			sql += " sum(case when (ns.q) = 2 then ((dgiao)) else 0 end) as dagiao2,";
			sql += " sum(case when (ns.q) = 3 then ((dgiao)) else 0 end) as dagiao3,";
			sql += " sum(case when (ns.q) = 4 then ((dgiao)) else 0 end) as dagiao4,";
			sql += " sum(case when (ns.q) = 1 then ((ntruoc)) else 0 end) as namtruoc1,";
			sql += " sum(case when (ns.q) = 2 then ((ntruoc)) else 0 end) as namtruoc2,";
			sql += " sum(case when (ns.q) = 3 then ((ntruoc)) else 0 end) as namtruoc3,";
			sql += " sum(case when (ns.q) = 4 then ((ntruoc)) else 0 end) as namtruoc4,";
			sql += " sum(case when (ns.q) = 1 then ((bsung)) else 0 end) as bosung1,";
			sql += " sum(case when (ns.q) = 2 then ((bsung)) else 0 end) as bosung2,";
			sql += " sum(case when (ns.q) = 3 then ((bsung)) else 0 end) as bosung3,";
			sql += " sum(case when (ns.q) = 4 then ((bsung)) else 0 end) as bosung4 ";
			sql += " FROM " + a.user + ".a_dutoanns" + s_yy +" ns ";
			if(s_IDtk!="")
				sql+=" WHERE ns.stk in(" + s_IDtk + ")" ;	
			if (s_IDChuong!="") 
				sql+=" AND ns.chuong="+s_IDChuong;
			if (s_IDHoatdong!="") 
				sql+=" AND ns.hoatdong="+s_IDHoatdong;
			if (s_IDNguongoc!="") 
				sql+=" AND ns.kp="+s_IDNguongoc;
			if (s_IDNhomMuc!="") 
				sql+=" AND ns.nhmuc="+s_IDNhomMuc;
			if (s_IDlk!="") 
				sql+=" AND ns.lk="+s_IDlk;
			sql += " ORDER BY ns.q";

			try
			{
				ds_Data = a.get_data(sql).Copy();				
				if(ds_Data==null||ds_Data.Tables[0].Rows.Count<=0)
					flag_dsnull=true;	
			}
			catch
			{
				flag_dsnull=true;
			}	
			if (flag_dsnull != true)
			{
				try
				{
					if ((ds_Data==null || ds_Data.Tables[0].Rows.Count<=0)) flag_dsnull=true;
					ds_Data.WriteXml("..\\xml\\KT_SoTheoDoiGiaoDuToan.xml",XmlWriteMode.WriteSchema);
				}
				catch{}
			}
			
			if (flag_dsnull) return null;
			else return ds_Data;
		}

		public DataSet SoTheoDoiNhanDuToan(AccessData a, string s_IDtk, string s_IDlk,string s_IDChuong, string s_IDHoatdong, string s_IDNguongoc,string s_IDNhomMuc,string s_tuthang,string s_denthang,string s_yy)
		{
			#region DATASET1 s_tuthang - s_denthang
			#region  cac field muc (ngaygs),sohieu(soctg),ngay,noidung,rutdutoan,lenhchi,ghithuchi,khac  trong khoang tu s_tuthang den s_denthang
			flag_dsnull = false;
			sql = "SELECT t1.*, t2.sodudauthang";
			sql += " FROM (";			
			sql += " SELECT DISTINCT ch.id as id, to_char(ct.ngaygs, 'dd/mm/yy') as ngaygs,ct.thanggs,ct.soctg as sohieu,to_char(ct.ngayg, 'dd/mm/yy') as ngay,";
			sql += " ctct.noidung as noidung, tk.stk as stk,nv.ten as nghiepvu,substr(ch.mtm,0,4) as muc,ch.mtm as mtm,ctct.stien as sotien,nv.id as idnghiepvu,";
			sql += " CASE WHEN (ctct.capphat=1) THEN ctct.stien ELSE 0 END as rutdutoan,";
			sql += " CASE WHEN (ctct.capphat=2) THEN ctct.stien ELSE 0 END as lenhchi,";
			sql += " CASE WHEN (ctct.capphat=4) THEN ctct.stien ELSE 0 END as ghithuchi,";
			sql += " CASE WHEN (ctct.capphat=5) THEN ctct.stien ELSE 0 END as khac,0 as khoiphuc,0 as bihuy,0 as sapxep";			
			sql += " FROM a_ctct" + s_yy + " ctct INNER JOIN a_ct"+s_yy+" ct ON ct.id=ctct.idct";
			sql += " INNER JOIN a_dmcapphat cp ON cp.id = ctct.capphat";
			sql += " LEFT JOIN a_nghiepvu nv ON nv.id=ct.nghiepvu";
			sql += " left JOIN a_dmtk tk ON ctct.tkcoa = tk.id";	
			sql += " LEFT JOIN a_dmng ng ON substr(tk.stk,7,length(trim(ng.mang)))=ng.mang OR substr(tk.stk,6,length(trim(ng.mang)))=ng.mang";
			sql += " LEFT JOIN a_dmch ch ON ch.id = ctct.mtmco";
			sql += " INNER JOIN a_dmnhom nhom ON ch.nhmuc=nhom.id";
			if(s_IDtk!="")
				sql += " WHERE ctct.tkcoa in(" + s_IDtk + ")" ;		
			if (s_IDChuong!="") 
				sql += " AND ct.chuong = " + s_IDChuong;
			if (s_IDHoatdong!="") 
				sql += " AND ct.hoatdong = " + s_IDHoatdong;
			if (s_IDNguongoc!="") 
				sql += " AND ng.id=" + s_IDNguongoc;			
			if (s_IDNhomMuc!="") 
				sql += " AND ch.nhmuc=" + s_IDNhomMuc;
			if (s_IDlk!="") 
				sql += " AND ctct.lk=" + s_IDlk;
			if (s_tuthang !="" || s_denthang!="")
				sql += " AND ct.thanggs BETWEEN "+ s_tuthang + " AND " + s_denthang;
			sql += " ) T1 INNER JOIN (";			
			sql += " SELECT ch.id as id, tk.stk,ch.mtm as mtm,sum(sdno" + s_tuthang + ") as sodudauthang";
			sql += " FROM a_sd" + s_yy + " sd INNER JOIN a_dmch ch on ch.id = sd.mtmuc INNER JOIN a_dmtk tk on tk.id = sd.stka";
			sql += " WHERE tk.stk like '008%' or tk.stk like '009%'";
			sql += " GROUP BY ch.mtm,tk.stk,ch.id ORDER BY tk.stk";
			sql += " ) T2 ON T1.id=T2.id AND T1.mtm =T2.mtm and T1.stk=T2.stk";			
			try
			{
				ds_Data = a.get_data(sql).Copy();
				if(ds_Data.Tables[0].Rows.Count<=0)
					flag_dsnull=true;
			}
			catch
			{
				flag_dsnull = true;
			}
			#endregion
			
			#region tinh KHOI PHUC,BI HUY CUA DATASET1
			if (flag_dsnull != true)
			{				
				int countRow=ds_Data.Tables[0].Rows.Count;		
				for(int j=0;j<countRow;j++)
				{		
					try
					{
						decimal sotien = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["sotien"].ToString());
						decimal rutdutoan = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["rutdutoan"].ToString());
						decimal lenhchi = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["lenhchi"].ToString());
						decimal ghithuchi = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["ghithuchi"].ToString());
						decimal khac = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["khac"].ToString());
						decimal khoiphuc = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["khoiphuc"].ToString());
						decimal bihuy = Convert.ToDecimal(ds_Data.Tables[0].Rows[j]["bihuy"].ToString());					
						int idnv = Convert.ToInt16(ds_Data.Tables[0].Rows[j]["idnghiepvu"].ToString());
					
						if (idnv==7)
						{
							khoiphuc += sotien;
							rutdutoan=0;
							lenhchi=0;
							ghithuchi=0;
							khac=0;
						}

						if (idnv==10)
						{
							bihuy += sotien;
							rutdutoan=0;
							lenhchi=0;
							ghithuchi=0;
							khac=0;
						}		
						ds_Data.Tables[0].Rows[j]["khoiphuc"] = khoiphuc;
						ds_Data.Tables[0].Rows[j]["bihuy"] = bihuy;
						ds_Data.Tables[0].Rows[j]["rutdutoan"] = rutdutoan;
						ds_Data.Tables[0].Rows[j]["lenhchi"] = lenhchi;
						ds_Data.Tables[0].Rows[j]["ghithuchi"] = ghithuchi;
						ds_Data.Tables[0].Rows[j]["khac"] = khac;
					}
					catch {}		
				}	
				
				ds_Data.AcceptChanges();
				//				ds_Data.WriteXml("..\\xml\\KT_bihuykhoiphuc.xml",XmlWriteMode.WriteSchema);
			#endregion
			#endregion
					
			#region DATASET2 1 - s_denthang
				
				#region  cac field muc (ngaygs),sohieu(soctg),ngay,noidung,rutdutoan,lenhchi,ghithuchi,khac  trong khoang tu 1 den s_denthang
				sql1 += " SELECT DISTINCT ch.id as id, to_char(ct.ngaygs, 'dd/mm/yy') as ngaygs,ct.thanggs,ct.soctg as sohieu,to_char(ct.ngayg, 'dd/mm/yy') as ngay,";
				sql1 += " ctct.noidung as noidung, tk.stk as stk,nv.ten as nghiepvu,substr(ch.mtm,0,4) as muc,ch.mtm as mtm,ctct.stien as sotien,nv.id as idnghiepvu,";
				sql1 += " CASE WHEN (ctct.capphat=1) THEN ctct.stien ELSE 0 END as rutdutoan,";
				sql1 += " CASE WHEN (ctct.capphat=2) THEN ctct.stien ELSE 0 END as lenhchi,";
				sql1 += " CASE WHEN (ctct.capphat=4) THEN ctct.stien ELSE 0 END as ghithuchi,";
				sql1 += " CASE WHEN (ctct.capphat=5) THEN ctct.stien ELSE 0 END as khac,0 as khoiphuc,0 as bihuy,1 as sapxep";
				sql1 += " ,0 as sum_rutdutoan, 0 as sum_lenhchi, 0 as sum_ghithuchi,0 as sum_khac,0 as sum_khoiphuc,0 as sum_bihuy";
				sql1 += " FROM a_ctct" + s_yy + " ctct INNER JOIN a_ct"+s_yy+" ct ON ct.id=ctct.idct";
				sql1 += " INNER JOIN a_dmcapphat cp ON cp.id = ctct.capphat";
				sql1 += " LEFT JOIN a_nghiepvu nv ON nv.id=ct.nghiepvu";
				sql1 += " INNER JOIN a_dmtk tk ON ctct.tkcoa = tk.id";	
				sql1 += " LEFT JOIN a_dmng ng ON substr(tk.stk,7,length(trim(ng.mang)))=ng.mang OR substr(tk.stk,6,length(trim(ng.mang)))=ng.mang";
				sql1 += " LEFT JOIN a_dmch ch ON ch.id = ctct.mtmco";
				sql += " INNER JOIN a_dmnhom nhom ON ch.nhmuc=nhom.id";
				if(s_IDtk!="")
					sql1 += " WHERE ctct.tkcoa in(" + s_IDtk + ")" ;		
				if (s_IDChuong!="") 
					sql1 += " AND ct.chuong = " + s_IDChuong;
				if (s_IDHoatdong!="") 
					sql1 += " AND ct.hoatdong = " + s_IDHoatdong;
				if (s_IDNguongoc!="") 
					sql1 += " AND ng.id=" + s_IDNguongoc;			
				if (s_IDNhomMuc!="") 
					sql += " AND ch.nhmuc=" + s_IDNhomMuc;
				if (s_IDlk!="") 
					sql1 += " AND ctct.lk=" + s_IDlk;
				if (s_tuthang !="" || s_denthang!="")
					sql1 += " AND ct.thanggs BETWEEN 1 AND " + s_denthang;
				
				try
				{
					ds_Data3 = a.get_data(sql1).Copy();
				}
				catch
				{
					flag_dsnull = true;
				}
				#endregion
		
				#region tinh KHOI PHUC,BI HUY CUA DATASET2
				if (flag_dsnull != true)
				{
					decimal sotien_ = 0;
					decimal rutdutoan_ = 0, sumrutdutoan_=0;
					decimal lenhchi_ = 0, sumlenhchi_=0;
					decimal ghithuchi_ = 0, sumghithuchi_=0;
					decimal khac_ = 0, sumkhac_=0;
					decimal khoiphuc_ = 0, sumkhoiphuc_=0;
					decimal bihuy_ = 0, sumbihuy_=0;
					int countRow1=ds_Data3.Tables[0].Rows.Count;		
					for(int j=0;j<countRow1;j++)
					{
						sotien_ = Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["sotien"].ToString());
						rutdutoan_ = Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["rutdutoan"].ToString());
						lenhchi_ = Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["lenhchi"].ToString());
						ghithuchi_ = Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["ghithuchi"].ToString());
						khac_ = Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["khac"].ToString());
						khoiphuc_ = Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["khoiphuc"].ToString());
						bihuy_ = Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["bihuy"].ToString());					
						int idnv_ = Convert.ToInt16(ds_Data3.Tables[0].Rows[j]["idnghiepvu"].ToString());
						if (idnv_==7)
						{
							khoiphuc_ += sotien_;
							rutdutoan_=0;
							lenhchi_=0;
							ghithuchi_=0;
							khac_=0;
						}

						if (idnv_==10)
						{
							bihuy_ += sotien_;
							rutdutoan_=0;
							lenhchi_=0;
							ghithuchi_=0;
							khac_=0;
						}				
						ds_Data3.Tables[0].Rows[j]["khoiphuc"] = khoiphuc_;
						ds_Data3.Tables[0].Rows[j]["bihuy"] = bihuy_;
						ds_Data3.Tables[0].Rows[j]["rutdutoan"] = rutdutoan_;
						ds_Data3.Tables[0].Rows[j]["lenhchi"] = lenhchi_;
						ds_Data3.Tables[0].Rows[j]["ghithuchi"] = ghithuchi_;
						ds_Data3.Tables[0].Rows[j]["khac"] = khac_;
					}	
			
					ds_Data3.AcceptChanges();
					//					ds_Data3.WriteXml("..\\xml\\DS3.xml",XmlWriteMode.WriteSchema);
					//				
					//
					#region tinh luy ke 
					for(int j=0;j<countRow1;j++)
					{
						sotien_ = Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["sotien"].ToString());
						rutdutoan_ = Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["rutdutoan"].ToString());
						lenhchi_ = Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["lenhchi"].ToString());
						ghithuchi_ = Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["ghithuchi"].ToString());
						khac_ = Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["khac"].ToString());
						khoiphuc_ = Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["khoiphuc"].ToString());
						bihuy_ = Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["bihuy"].ToString());					
						int idnv_ = Convert.ToInt16(ds_Data3.Tables[0].Rows[j]["idnghiepvu"].ToString());
						sumrutdutoan_+=rutdutoan_;
						sumlenhchi_+=lenhchi_;
						sumghithuchi_+=ghithuchi_;
						sumkhac_+=khac_;
						sumkhoiphuc_+=khoiphuc_;
						sumbihuy_+=bihuy_;		
						
					}				
				
					ds_Data3.Tables[0].Rows[countRow1-1]["sum_khoiphuc"] = sumkhoiphuc_;
					ds_Data3.Tables[0].Rows[countRow1-1]["sum_bihuy"] = sumbihuy_;
					ds_Data3.Tables[0].Rows[countRow1-1]["sum_rutdutoan"] = sumrutdutoan_;
					ds_Data3.Tables[0].Rows[countRow1-1]["sum_lenhchi"] = sumlenhchi_;
					ds_Data3.Tables[0].Rows[countRow1-1]["sum_ghithuchi"] = sumghithuchi_;
					ds_Data3.Tables[0].Rows[countRow1-1]["sum_khac"] = sumkhac_;
					ds_Data3.AcceptChanges();
					//					ds_Data3.WriteXml("..\\xml\\DS3.xml",XmlWriteMode.WriteSchema);
					#endregion
					
				}
			#endregion									

			#endregion
				
				try
				{
					if ((ds_Data==null || ds_Data.Tables[0].Rows.Count<=0)) flag_dsnull=true;
					else
					{							
						ds_Data.Merge(ds_Data3);						
					}
					if ((ds_Data==null || ds_Data.Tables[0].Rows.Count<=0)) flag_dsnull=true;
					//					ds_Data.WriteXml("..\\xml\\KT_SoTheoDoiNhanDuToan.xml",XmlWriteMode.WriteSchema);
				}
				catch {}			
			}
			if (flag_dsnull) return null;
			else return ds_Data;
		}

		public DataSet ds_tc_fsmKPI_la(LibKetoan.AccessData a,string s_IDlk,string s_mm, string s_mm1, string s_yy, string s_yyyy, string s_IDChuong,  string s_IDHoatDong, string s_IDMuc, string s_IDNhombc, string s_IDNguon)
		{
			//tinh fat sinh
			sql=tc_fsmKPI(a,s_IDlk,s_mm,s_mm1,s_yy,s_yyyy,s_IDChuong,s_IDHoatDong,s_IDMuc,s_IDNhombc,s_IDNguon);
			//duyet toan danh sach, do du lieu vao cot thich hop
			ds_Data=a.get_data(sql);
			if(ds_Data!=null && ds_Data.Tables[0].Rows.Count>0)
			{
				int i_countfs=ds_Data.Tables[0].Rows.Count-1;
				string s_mang="",s_tkno="",s_tkco="",s_ngvu="";
				decimal d_no=0,d_co=0;
				#region//khai bao bien 
				//hoat dong thuong xuyen				
				decimal d_302=0,d_302no=0,d_302co=0,d_306=0,d_306no=0,d_306co=0,d_308=0;
				decimal d_402=0,d_402no=0,d_402co=0,d_406=0,d_406no=0,d_406co=0,d_408=0;
				decimal d_502=0,d_502no=0,d_502co=0,d_506=0,d_506no=0,d_506co=0,d_508=0;
				decimal d_602=0,d_602no=0,d_602co=0,d_606=0,d_606no=0,d_606co=0,d_608=0;
				decimal d_802=0,d_802no=0,d_802co=0,d_806=0,d_806no=0,d_806co=0,d_808=0;
				decimal d_902=0,d_902no=0,d_902co=0,d_906=0,d_906no=0,d_906co=0,d_908=0;
				decimal d_1002=0,d_1002no=0,d_1002co=0,d_1006=0,d_1006no=0,d_1006co=0,d_1008=0;
				decimal d_1102=0,d_1102no=0,d_1102co=0,d_1106=0,d_1106no=0,d_1106co=0,d_1108=0;

				//khai bao bien du an 				
				decimal d_302_=0,d_302no_=0,d_302co_=0,d_306_=0,d_306no_=0,d_306co_=0,d_308_=0;
				decimal d_402_=0,d_402no_=0,d_402co_=0,d_406_=0,d_406no_=0,d_406co_=0,d_408_=0;
				decimal d_502_=0,d_502no_=0,d_502co_=0,d_506_=0,d_506no_=0,d_506co_=0,d_508_=0;
				decimal d_602_=0,d_602no_=0,d_602co_=0,d_606_=0,d_606no_=0,d_606co_=0,d_608_=0;
				decimal d_802_=0,d_802no_=0,d_802co_=0,d_806_=0,d_806no_=0,d_806co_=0,d_808_=0;
				decimal d_902_=0,d_902no_=0,d_902co_=0,d_906_=0,d_906no_=0,d_906co_=0,d_908_=0;
				decimal d_1002_=0,d_1002no_=0,d_1002co_=0,d_1006_=0,d_1006no_=0,d_1006co_=0,d_1008_=0;
				decimal d_1102_=0,d_1102no_=0,d_1102co_=0,d_1106_=0,d_1106no_=0,d_1106co_=0,d_1108_=0;

				//khai bao bien hoat dong khong thuong xuyen			
				decimal d_312=0,d_312no=0,d_312co=0,d_316=0,d_316no=0,d_316co=0,d_318=0;
				decimal d_412=0,d_412no=0,d_412co=0,d_416=0,d_416no=0,d_416co=0,d_418=0;
				decimal d_512=0,d_512no=0,d_512co=0,d_516=0,d_516no=0,d_516co=0,d_518=0;
				decimal d_612=0,d_612no=0,d_612co=0,d_616=0,d_616no=0,d_616co=0,d_618=0;
				decimal d_812=0,d_812no=0,d_812co=0,d_816=0,d_816no=0,d_816co=0,d_818=0;
				decimal d_912=0,d_912no=0,d_912co=0,d_916=0,d_916no=0,d_916co=0,d_918=0;
				decimal d_1012=0,d_1012no=0,d_1012co=0,d_1016=0,d_1016no=0,d_1016co=0,d_1018=0;
				decimal d_1112=0,d_1112no=0,d_1112co=0,d_1116=0,d_1116no=0,d_1116co=0,d_1118=0;
				#endregion 
				
				for(int i=0;i<=i_countfs;i++)
				{
					//khoi tao lai gia tri bang 0
					#region khoi tao gia tri cho bien
					//hoat dong thuong xuyen
					d_302=0;d_302no=0;d_302co=0;d_306=0;d_306no=0;d_306co=0;d_308=0;
					d_402=0;d_402no=0;d_402co=0;d_406=0;d_406no=0;d_406co=0;d_408=0;
					d_502=0;d_502no=0;d_502co=0;d_506=0;d_506no=0;d_506co=0;d_508=0;
					d_602=0;d_602no=0;d_602co=0;d_606=0;d_606no=0;d_606co=0;d_608=0;
					d_802=0;d_802no=0;d_802co=0;d_806=0;d_806no=0;d_806co=0;d_808=0;
					d_902=0;d_902no=0;d_902co=0;d_906=0;d_906no=0;d_906co=0;d_908=0;
					d_1002=0;d_1002no=0;d_1002co=0;d_1006=0;d_1006no=0;d_1006co=0;d_1008=0;
					d_1102=0;d_1102no=0;d_1102co=0;d_1106=0;d_1106no=0;d_1106co=0;d_1108=0;
					
					//du an 
					d_302_=0;d_302no_=0;d_302co_=0;d_306_=0;d_306no_=0;d_306co_=0;d_308_=0;
					d_402_=0;d_402no_=0;d_402co_=0;d_406_=0;d_406no_=0;d_406co_=0;d_408_=0;
					d_502_=0;d_502no_=0;d_502co_=0;d_506_=0;d_506no_=0;d_506co_=0;d_508_=0;
					d_602_=0;d_602no_=0;d_602co_=0;d_606_=0;d_606no_=0;d_606co_=0;d_608_=0;
					d_802_=0;d_802no_=0;d_802co_=0;d_806_=0;d_806no_=0;d_806co_=0;d_808_=0;
					d_902_=0;d_902no_=0;d_902co_=0;d_906_=0;d_906no_=0;d_906co_=0;d_908_=0;
					d_1002_=0;d_1002no_=0;d_1002co_=0;d_1006_=0;d_1006no_=0;d_1006co_=0;d_1008_=0;
					d_1102_=0;d_1102no_=0;d_1102co_=0;d_1106_=0;d_1106no_=0;d_1106co_=0;d_1108_=0;

					//hoat dong khong thuong xuyen
					d_312=0;d_312no=0;d_312co=0;d_316=0;d_316no=0;d_316co=0;d_318=0;
					d_412=0;d_412no=0;d_412co=0;d_416=0;d_416no=0;d_416co=0;d_418=0;
					d_512=0;d_512no=0;d_512co=0;d_516=0;d_516no=0;d_516co=0;d_518=0;
					d_612=0;d_612no=0;d_612co=0;d_616=0;d_616no=0;d_616co=0;d_618=0;
					d_812=0;d_812no=0;d_812co=0;d_816=0;d_816no=0;d_816co=0;d_818=0;
					d_912=0;d_912no=0;d_912co=0;d_916=0;d_916no=0;d_916co=0;d_918=0;
					d_1012=0;d_1012no=0;d_1012co=0;d_1016=0;d_1016no=0;d_1016co=0;d_1018=0;
					d_1112=0;d_1112no=0;d_1112co=0;d_1116=0;d_1116no=0;d_1116co=0;d_1118=0;
					#endregion 

					//khoi tao gia tri cho cac bien
					s_ngvu=ds_Data.Tables[0].Rows[i]["idnghiepvu"].ToString();
					s_mang=ds_Data.Tables[0].Rows[i]["mang"].ToString();
					s_tkno=ds_Data.Tables[0].Rows[i]["tkno"].ToString();
					s_tkco=ds_Data.Tables[0].Rows[i]["tkco"].ToString();
					d_no=Convert.ToDecimal(ds_Data.Tables[0].Rows[i]["no"].ToString());
					d_co=Convert.ToDecimal(ds_Data.Tables[0].Rows[i]["co"].ToString());
					#region kiem tra ma nguon do so lieu fat sinh vao ds
					//kiem tra dk, do so lieu
					if(s_mang.Trim()=="0113" )
					{
						if(s_tkno.Trim()!="" || s_tkco.Trim()!="")
						{
							//hoat dong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_308+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66121"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_306no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66111") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66121")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_306co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46111") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_302co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_302no+=d_no;
							d_302=d_302co-d_302no;
							d_306=d_306no-d_306co;							

							//hoat dong khong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_318+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66122"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_316no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66112") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66122")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_316co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46112") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_312co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_312no+=d_no;
							d_312=d_312co-d_312no;
							d_316=d_316no-d_316co;

							//du an 
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && (s_ngvu=="8" || s_ngvu=="7"))
								d_308_+=d_no;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
								d_306no_+=d_no;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
								d_306co_+=d_co;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_302co_+=d_co;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_302no_+=d_no;
							d_302_=d_302co_-d_302no_;
							d_306_=d_306no_-d_306co_;							
						}
					}
					else
						if(s_mang.Trim()=="0212")
					{
						if(s_tkno.Trim()!="" || s_tkco.Trim()!="")
						{
							//hoat dong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_408+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66121"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_406no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66111") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66121")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_406co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46111") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_402co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_402no+=d_no;
							d_402=d_402co-d_402no;
							d_406=d_406no-d_406co;

							//hoat dong khong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_418+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66122"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_416no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66112") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66122")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_416co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46112") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_412co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_412no+=d_no;
							d_412=d_412co-d_412no;
							d_416=d_416no-d_416co;

							//du an
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462"&& (s_ngvu=="8" || s_ngvu=="7"))
								d_408_+=d_no;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662"&& s_ngvu!="8"&&s_ngvu!="7")	
								d_406no_+=d_no;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
								d_406co_+=d_co;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_402co_+=d_co;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_402no_+=d_no;
							d_402_=d_402co_-d_402no_;
							d_406_=d_406no_-d_406co_;							
						}
					}
					else
						if(s_mang.Trim()=="0214")
					{
						if(s_tkno.Trim()!="" || s_tkco.Trim()!="")
						{
							//hoat dong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_508+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66121"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_506no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66111") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66121")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_506co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46111") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_502co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_502no+=d_no;
							d_502=d_502co-d_502no;
							d_506=d_506no-d_506co;

							//hoat dong khong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_518+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66122"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_516no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66112") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66122")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_516co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46112") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_512co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_512no+=d_no;
							d_512=d_512co-d_512no;
							d_516=d_516no-d_516co;

							//du an
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462"&& (s_ngvu=="8" || s_ngvu=="7"))
								d_508_+=d_no;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662"&& s_ngvu!="8"&&s_ngvu!="7")	
								d_506no_+=d_no;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
								d_506co_+=d_co;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_502co_+=d_co;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_502no_+=d_no;
							d_502_=d_502co_-d_502no_;
							d_506_=d_506no_-d_506co_;							
						}
					}
					else 					
						if(s_mang.Trim()=="0218")
						{
							if(s_tkno.Trim()!="" || s_tkco.Trim()!="")
							{
								//hoat dong thuong xuyen 
								if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121"))&& (s_ngvu=="8" || s_ngvu=="7"))
									d_608+=d_no;
								if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66121"))&& s_ngvu!="8"&&s_ngvu!="7")	
									d_606no+=d_no;
								if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66111") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66121")) && s_ngvu!="8"&&s_ngvu!="7")	
									d_606co+=d_co;
								if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46111") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
									d_602co+=d_co;
								if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
									d_602no+=d_no;
								d_602=d_602co-d_602no;
								d_606=d_606no-d_606co;

								//hoat dong khong thuong xuyen
								if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122"))&& (s_ngvu=="8" || s_ngvu=="7"))
									d_618+=d_no;
								if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66122"))&& s_ngvu!="8"&&s_ngvu!="7")	
									d_616no+=d_no;
								if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66112") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66122")) && s_ngvu!="8"&&s_ngvu!="7")	
									d_616co+=d_co;
								if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46112") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
									d_612co+=d_co;
								if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
									d_612no+=d_no;
								d_612=d_612co-d_612no;
								d_616=d_616no-d_616co;

								//du an
								if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462"&& (s_ngvu=="8" || s_ngvu=="7"))
									d_608_+=d_no;
								if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662"&& s_ngvu!="8"&&s_ngvu!="7")	
									d_606no_+=d_no;
								if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
									d_606co_+=d_co;
								if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
									d_602co_+=d_co;
								if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
									d_602no_+=d_no;
								d_602_=d_602co_-d_602no_;
								d_606_=d_606no_-d_606co_;
							}
						}					
						else 						
							if(s_mang.Trim()=="0401")
							{
								if(s_tkno.Trim()!="" || s_tkco.Trim()!="")
								{
									//hoat dong thuong xuyen 
									if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121"))&& (s_ngvu=="8" || s_ngvu=="7"))
										d_808+=d_no;
									if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66121"))&& s_ngvu!="8"&&s_ngvu!="7")	
										d_806no+=d_no;
									if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66111") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66121")) && s_ngvu!="8"&&s_ngvu!="7")	
										d_806co+=d_co;
									if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46111") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
										d_802co+=d_co;
									if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
										d_802no+=d_no;
									d_802=d_802co-d_802no;
									d_806=d_806no-d_806co;

									//hoat dong khong thuong xuyen
									if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122"))&& (s_ngvu=="8" || s_ngvu=="7"))
										d_818+=d_no;
									if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66122"))&& s_ngvu!="8"&&s_ngvu!="7")	
										d_816no+=d_no;
									if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66112") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66122")) && s_ngvu!="8"&&s_ngvu!="7")	
										d_816co+=d_co;
									if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46112") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
										d_812co+=d_co;
									if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
										d_812no+=d_no;
									d_812=d_812co-d_812no;
									d_816=d_816no-d_816co;

									//du an
									if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462"&& (s_ngvu=="8" || s_ngvu=="7"))
										d_808_+=d_no;
									if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662"&& s_ngvu!="8"&&s_ngvu!="7")	
										d_806no_+=d_no;
									if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
										d_806co_+=d_co;
									if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
										d_802co_+=d_co;
									if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
										d_802no_+=d_no;
									d_802_=d_802co_-d_802no_;
									d_806_=d_806no_-d_806co_;
								}
								
							}
						else 						
							if(s_mang.Trim()=="0501")
							{
								if(s_tkno.Trim()!="" || s_tkco.Trim()!="")
								{
									//hoat dong thuong xuyen 
									if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121"))&& (s_ngvu=="8" || s_ngvu=="7"))
										d_908+=d_no;
									if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66121"))&& s_ngvu!="8"&&s_ngvu!="7")	
										d_906no+=d_no;
									if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66111") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66121")) && s_ngvu!="8"&&s_ngvu!="7")	
										d_906co+=d_co;
									if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46111") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
										d_902co+=d_co;
									if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
										d_902no+=d_no;
									d_902=d_902co-d_902no;
									d_906=d_906no-d_906co;

									//hoat dong khong thuong xuyen
									if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122"))&& (s_ngvu=="8" || s_ngvu=="7"))
										d_918+=d_no;
									if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66122"))&& s_ngvu!="8"&&s_ngvu!="7")	
										d_916no+=d_no;
									if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66112") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66122")) && s_ngvu!="8"&&s_ngvu!="7")	
										d_916co+=d_co;
									if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46112") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
										d_912co+=d_co;
									if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
										d_912no+=d_no;
									d_912=d_912co-d_912no;
									d_916=d_916no-d_916co;

									//du an
									if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462"&& (s_ngvu=="8" || s_ngvu=="7"))
										d_908_+=d_no;
									if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662"&& s_ngvu!="8"&&s_ngvu!="7")	
										d_906no_+=d_no;
									if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
										d_906co_+=d_co;
									if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
										d_902co_+=d_co;
									if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
										d_902no_+=d_no;
									d_902_=d_902co_-d_902no_;
									d_906_=d_906no_-d_906co_;
								}
								
							}
						else 
						if(s_mang.Trim()=="0402")
					{
						if(s_tkno.Trim()!="" || s_tkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_1008+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66121"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_1006no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66111") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66121")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_1006co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46111") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_1002co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_1002no+=d_no;
							d_1002=d_1002co-d_1002no;
							d_1006=d_1006no-d_1006co;

							//hoat dong khong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_1018+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66122"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_1016no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66112") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66122")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_1016co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46112") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_1012co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_1012no+=d_no;
							d_1012=d_1012co-d_1012no;
							d_1016=d_1016no-d_1016co;

							//du an
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462"&& (s_ngvu=="8" || s_ngvu=="7"))
								d_1008_+=d_no;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662"&& s_ngvu!="8"&&s_ngvu!="7")	
								d_1006no_+=d_no;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
								d_1006co_+=d_co;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_1002co_+=d_co;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_1002no_+=d_no;
							d_1002_=d_1002co_-d_1002no_;
							d_1006_=d_1006no_-d_1006co_;
						}
								
					}
					else
						if(s_mang.Trim()=="0502")
					{
						if(s_tkno.Trim()!="" || s_tkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_1108+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66121"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_1106no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66111") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66121")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_1106co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46111") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_1102co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_1102no+=d_no;
							d_1102=d_1102co-d_1102no;
							d_1106=d_1106no-d_1106co;

							//hoat dong khong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_1118+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66122"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_1116no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66112") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66122")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_1116co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46112") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_1112co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_1112no+=d_no;
							d_1112=d_1112co-d_1112no;
							d_1116=d_1116no-d_1116co;

							//du an
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462"&& (s_ngvu=="8" || s_ngvu=="7"))
								d_1108_+=d_no;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662"&& s_ngvu!="8"&&s_ngvu!="7")	
								d_1106no_+=d_no;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
								d_1106co_+=d_co;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_1102co_+=d_co;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_1102no_+=d_no;
							d_1102_=d_1102co_-d_1102no_;
							d_1106_=d_1106no_-d_1106co_;
						}
								
					}
					#endregion
					if(((s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462")|| (s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662"))
						|| ((s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462")|| (s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662")))
						ds_Data.Tables[0].Rows[i]["phanloai"]="II";
					else
						if(((s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="461")|| (s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="661"))
						|| ((s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="461")|| (s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="661")))
						ds_Data.Tables[0].Rows[i]["phanloai"]="I";
					#region add them dong fat sinh vao ds
					//hoat dong
					ds_Data.Tables[0].Rows[i]["d302"]=d_302;
					ds_Data.Tables[0].Rows[i]["d306"]=d_306;
					ds_Data.Tables[0].Rows[i]["d308"]=d_308;

					ds_Data.Tables[0].Rows[i]["d312"]=d_312;
					ds_Data.Tables[0].Rows[i]["d316"]=d_316;
					ds_Data.Tables[0].Rows[i]["d318"]=d_318;

					ds_Data.Tables[0].Rows[i]["d402"]=d_402;
					ds_Data.Tables[0].Rows[i]["d406"]=d_406;
					ds_Data.Tables[0].Rows[i]["d408"]=d_408;

					ds_Data.Tables[0].Rows[i]["d412"]=d_412;
					ds_Data.Tables[0].Rows[i]["d416"]=d_416;
					ds_Data.Tables[0].Rows[i]["d418"]=d_418;

					ds_Data.Tables[0].Rows[i]["d502"]=d_502;
					ds_Data.Tables[0].Rows[i]["d506"]=d_506;
					ds_Data.Tables[0].Rows[i]["d508"]=d_508;

					ds_Data.Tables[0].Rows[i]["d512"]=d_512;
					ds_Data.Tables[0].Rows[i]["d516"]=d_516;
					ds_Data.Tables[0].Rows[i]["d518"]=d_518;

					ds_Data.Tables[0].Rows[i]["d602"]=d_602;
					ds_Data.Tables[0].Rows[i]["d606"]=d_606;
					ds_Data.Tables[0].Rows[i]["d608"]=d_608;

					ds_Data.Tables[0].Rows[i]["d612"]=d_612;
					ds_Data.Tables[0].Rows[i]["d616"]=d_616;
					ds_Data.Tables[0].Rows[i]["d618"]=d_618;

					
					ds_Data.Tables[0].Rows[i]["d802"]=d_802;
					ds_Data.Tables[0].Rows[i]["d806"]=d_806;
					ds_Data.Tables[0].Rows[i]["d808"]=d_808;

					ds_Data.Tables[0].Rows[i]["d812"]=d_812;
					ds_Data.Tables[0].Rows[i]["d816"]=d_816;
					ds_Data.Tables[0].Rows[i]["d818"]=d_818;

					
					ds_Data.Tables[0].Rows[i]["d902"]=d_902;
					ds_Data.Tables[0].Rows[i]["d906"]=d_906;
					ds_Data.Tables[0].Rows[i]["d908"]=d_908;

					ds_Data.Tables[0].Rows[i]["d912"]=d_912;
					ds_Data.Tables[0].Rows[i]["d916"]=d_916;
					ds_Data.Tables[0].Rows[i]["d918"]=d_918;

					
					ds_Data.Tables[0].Rows[i]["d1002"]=d_1002;
					ds_Data.Tables[0].Rows[i]["d1006"]=d_1006;
					ds_Data.Tables[0].Rows[i]["d1008"]=d_1008;

					ds_Data.Tables[0].Rows[i]["d1012"]=d_1012;
					ds_Data.Tables[0].Rows[i]["d1016"]=d_1016;
					ds_Data.Tables[0].Rows[i]["d1018"]=d_1018;

					//du an
					ds_Data.Tables[0].Rows[i]["d302_"]=d_302_;
					ds_Data.Tables[0].Rows[i]["d306_"]=d_306_;
					ds_Data.Tables[0].Rows[i]["d308_"]=d_308_;					

					ds_Data.Tables[0].Rows[i]["d402_"]=d_402_;
					ds_Data.Tables[0].Rows[i]["d406_"]=d_406_;
					ds_Data.Tables[0].Rows[i]["d408_"]=d_408_;

					ds_Data.Tables[0].Rows[i]["d502_"]=d_502_;
					ds_Data.Tables[0].Rows[i]["d506_"]=d_506_;
					ds_Data.Tables[0].Rows[i]["d508_"]=d_508_;

					ds_Data.Tables[0].Rows[i]["d602_"]=d_602_;
					ds_Data.Tables[0].Rows[i]["d606_"]=d_606_;
					ds_Data.Tables[0].Rows[i]["d608_"]=d_608_;

					ds_Data.Tables[0].Rows[i]["d802_"]=d_802_;
					ds_Data.Tables[0].Rows[i]["d806_"]=d_806_;
					ds_Data.Tables[0].Rows[i]["d808_"]=d_808_;

					ds_Data.Tables[0].Rows[i]["d902_"]=d_902_;
					ds_Data.Tables[0].Rows[i]["d906_"]=d_906_;
					ds_Data.Tables[0].Rows[i]["d908_"]=d_908_;

					ds_Data.Tables[0].Rows[i]["d1002_"]=d_1002_;
					ds_Data.Tables[0].Rows[i]["d1006_"]=d_1006_;
					ds_Data.Tables[0].Rows[i]["d1008_"]=d_1008_;

					ds_Data.Tables[0].Rows[i]["d1102_"]=d_1102_;
					ds_Data.Tables[0].Rows[i]["d1106_"]=d_1106_;
					ds_Data.Tables[0].Rows[i]["d1108_"]=d_1108_;
					#endregion
				}
			}	
			//tinh so du dau ky
			try
			{
				ds_Data2=a.get_SdDauKy_mKPI(s_yy,s_mm,s_IDMuc,s_IDlk,s_IDChuong,s_IDHoatDong,s_IDNhombc,s_IDNguon);
				if(ds_Data2!=null)
					ds_Data.Merge(ds_Data2);
				ds_Data.AcceptChanges();
			}
			catch{flag_dsnull=true;};
			//tinh luyke
			sql1=tc_fsmKPI(a,s_IDlk,"01",s_mm1,s_yy,s_yyyy,s_IDChuong,s_IDHoatDong,s_IDMuc,s_IDNhombc,s_IDNguon);
			ds_Data3=a.get_data(sql1);
			if(ds_Data3!=null && ds_Data3.Tables[0].Rows.Count>0)
			{				
				int i_countlk=ds_Data3.Tables[0].Rows.Count-1;
				string s_lkmang="",s_lktkno="",s_lktkco="",s_lkngvu="";
				decimal d_lkno=0,d_lkco=0;
				#region khai bao bien cho luy ke
				//khai bao bien hoat dong thuong xuyen
				decimal d_303=0,d_303no=0,d_303co=0,d_307=0,d_307no=0,d_307co=0,d_309=0;
				decimal d_403=0,d_403no=0,d_403co=0,d_407=0,d_407no=0,d_407co=0,d_409=0;
				decimal d_503=0,d_503no=0,d_503co=0,d_507=0,d_507no=0,d_507co=0,d_509=0;
				decimal d_603=0,d_603no=0,d_603co=0,d_607=0,d_607no=0,d_607co=0,d_609=0;
				decimal d_803=0,d_803no=0,d_803co=0,d_807=0,d_807no=0,d_807co=0,d_809=0;
				decimal d_903=0,d_903no=0,d_903co=0,d_907=0,d_907no=0,d_907co=0,d_909=0;
				decimal d_1003=0,d_1003no=0,d_1003co=0,d_1007=0,d_1007no=0,d_1007co=0,d_1009=0;
				decimal d_1103=0,d_1103no=0,d_1103co=0,d_1107=0,d_1107no=0,d_1107co=0,d_1109=0;

				//khai bao bien du an
				decimal d_303_=0,d_303no_=0,d_303co_=0,d_307_=0,d_307no_=0,d_307co_=0,d_309_=0;
				decimal d_403_=0,d_403no_=0,d_403co_=0,d_407_=0,d_407no_=0,d_407co_=0,d_409_=0;
				decimal d_503_=0,d_503no_=0,d_503co_=0,d_507_=0,d_507no_=0,d_507co_=0,d_509_=0;
				decimal d_603_=0,d_603no_=0,d_603co_=0,d_607_=0,d_607no_=0,d_607co_=0,d_609_=0;
				decimal d_803_=0,d_803no_=0,d_803co_=0,d_807_=0,d_807no_=0,d_807co_=0,d_809_=0;
				decimal d_903_=0,d_903no_=0,d_903co_=0,d_907_=0,d_907no_=0,d_907co_=0,d_909_=0;
				decimal d_1003_=0,d_1003no_=0,d_1003co_=0,d_1007_=0,d_1007no_=0,d_1007co_=0,d_1009_=0;
				decimal d_1103_=0,d_1103no_=0,d_1103co_=0,d_1107_=0,d_1107no_=0,d_1107co_=0,d_1109_=0;

				//khai bao bien hoat dong khong thuong xuyen
				decimal d_313=0,d_313no=0,d_313co=0,d_317=0,d_317no=0,d_317co=0,d_319=0;
				decimal d_413=0,d_413no=0,d_413co=0,d_417=0,d_417no=0,d_417co=0,d_419=0;
				decimal d_513=0,d_513no=0,d_513co=0,d_517=0,d_517no=0,d_517co=0,d_519=0;
				decimal d_613=0,d_613no=0,d_613co=0,d_617=0,d_617no=0,d_617co=0,d_619=0;
				decimal d_813=0,d_813no=0,d_813co=0,d_817=0,d_817no=0,d_817co=0,d_819=0;
				decimal d_913=0,d_913no=0,d_913co=0,d_917=0,d_917no=0,d_917co=0,d_919=0;
				decimal d_1013=0,d_1013no=0,d_1013co=0,d_1017=0,d_1017no=0,d_1017co=0,d_1019=0;
				decimal d_1113=0,d_1113no=0,d_1113co=0,d_1117=0,d_1117no=0,d_1117co=0,d_1119=0;
				#endregion
				
				for(int j=0;j<=i_countlk;j++)
				{
					#region khoi tao gia tri cho bien
					//khoi tao lai gia tri bang 0
					//hoat dong thuong xuyen
					d_303=0;d_303no=0;d_303co=0;d_307=0;d_307no=0;d_307co=0;d_309=0;
					d_403=0;d_403no=0;d_403co=0;d_407=0;d_407no=0;d_407co=0;d_409=0;
					d_503=0;d_503no=0;d_503co=0;d_507=0;d_507no=0;d_507co=0;d_509=0;
					d_603=0;d_603no=0;d_603co=0;d_607=0;d_607no=0;d_607co=0;d_609=0;
					d_803=0;d_803no=0;d_803co=0;d_807=0;d_807no=0;d_807co=0;d_809=0;
					d_903=0;d_903no=0;d_903co=0;d_907=0;d_907no=0;d_907co=0;d_909=0;
					d_1003=0;d_1003no=0;d_1003co=0;d_1007=0;d_1007no=0;d_1007co=0;d_1009=0;
					d_1103=0;d_1103no=0;d_1103co=0;d_1107=0;d_1107no=0;d_1107co=0;d_1109=0;
				
					//du an
					d_303_=0;d_303no_=0;d_303co_=0;d_307_=0;d_307no_=0;d_307co_=0;d_309_=0;
					d_403_=0;d_403no_=0;d_403co_=0;d_407_=0;d_407no_=0;d_407co_=0;d_409_=0;
					d_503_=0;d_503no_=0;d_503co_=0;d_507_=0;d_507no_=0;d_507co_=0;d_509_=0;
					d_603_=0;d_603no_=0;d_603co_=0;d_607_=0;d_607no_=0;d_607co_=0;d_609_=0;
					d_803_=0;d_803no_=0;d_803co_=0;d_807_=0;d_807no_=0;d_807co_=0;d_809_=0;
					d_903_=0;d_903no_=0;d_903co_=0;d_907_=0;d_907no_=0;d_907co_=0;d_909_=0;
					d_1003_=0;d_1003no_=0;d_1003co_=0;d_1007_=0;d_1007no_=0;d_1007co_=0;d_1009_=0;
					d_1103_=0;d_1103no_=0;d_1103co_=0;d_1107_=0;d_1107no_=0;d_1107co_=0;d_1109_=0;

					//hoat dong khong thuong xuyen
					d_313=0;d_313no=0;d_313co=0;d_317=0;d_317no=0;d_317co=0;d_319=0;
					d_413=0;d_413no=0;d_413co=0;d_417=0;d_417no=0;d_417co=0;d_419=0;
					d_513=0;d_513no=0;d_513co=0;d_517=0;d_517no=0;d_517co=0;d_519=0;
					d_613=0;d_613no=0;d_613co=0;d_617=0;d_617no=0;d_617co=0;d_619=0;
					d_813=0;d_813no=0;d_813co=0;d_817=0;d_817no=0;d_817co=0;d_819=0;
					d_913=0;d_913no=0;d_913co=0;d_917=0;d_917no=0;d_917co=0;d_919=0;
					d_1013=0;d_1013no=0;d_1013co=0;d_1017=0;d_1017no=0;d_1017co=0;d_1019=0;
					d_1113=0;d_1113no=0;d_1113co=0;d_1117=0;d_1117no=0;d_1117co=0;d_1119=0;
					
					//khoi tao gia tri cho cac bien
					s_lkngvu=ds_Data3.Tables[0].Rows[j]["idnghiepvu"].ToString();
					s_lkmang=ds_Data3.Tables[0].Rows[j]["mang"].ToString();
					s_lktkno=ds_Data3.Tables[0].Rows[j]["tkno"].ToString();
					s_lktkco=ds_Data3.Tables[0].Rows[j]["tkco"].ToString();
					d_lkno=Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["no"].ToString());
					d_lkco=Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["co"].ToString());
					#endregion 

					#region kiem tra nguon do so lieu vao ds
					//kiem tra dk, do so lieu
					if(s_lkmang.Trim()=="0113" )
					{
						if(s_lktkno.Trim()!="" || s_lktkco.Trim()!="")
						{
							//hoat dong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_309+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66121"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_307no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66111") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66121")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_307co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46111") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_303co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_303no+=d_lkno;
							d_303=d_303co-d_303no;
							d_307=d_307no-d_307co;							

							//hoat dong khong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_319+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66122"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_317no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66112") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66122")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_317co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46112") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_313co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_313no+=d_lkno;
							d_313=d_313co-d_313no;
							d_317=d_317no-d_317co;

							//du an
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && (s_lkngvu=="8" || s_lkngvu=="7"))
								d_309_+=d_lkno;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_307no_+=d_lkno;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_307co_+=d_lkco;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_303co_+=d_lkco;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_303no_+=d_lkno;
							d_303_=d_303co_-d_303no_;
							d_307_=d_307no_-d_307co_;
							
						}
					}
					else
						if(s_lkmang.Trim()=="0212")
					{
						if(s_lktkno.Trim()!="" || s_lktkco.Trim()!="")
						{
							//hoat dong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_409+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66121"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_407no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66111") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66121")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_407co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46111") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_403co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_403no+=d_lkno;
							d_403=d_403co-d_403no;
							d_407=d_407no-d_407co;

							//hoat dong khong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_419+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66122"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_417no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66112") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66122")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_417co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46112") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_413co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_413no+=d_lkno;
							d_413=d_413co-d_413no;
							d_417=d_417no-d_417co;

							//du an 
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462"&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_409_+=d_lkno;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662"&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_407no_+=d_lkno;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_407co_+=d_lkco;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_403co_+=d_lkco;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_403no_+=d_lkno;
							d_403_=d_403co_-d_403no_;
							d_407_=d_407no_-d_407co_;
						}
					}
					else
						if(s_lkmang.Trim()=="0214")
					{
						if(s_lktkno.Trim()!="" || s_lktkco.Trim()!="")
						{
							//hoat dong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_509+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66121"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_507no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66111") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66121")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_507co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46111") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_503co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_503no+=d_lkno;
							d_503=d_503co-d_503no;
							d_507=d_507no-d_507co;

							//hoat dong khong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_519+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66122"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_517no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66112") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66122")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_517co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46112") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_513co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_513no+=d_lkno;
							d_513=d_513co-d_513no;
							d_517=d_517no-d_517co;

							//du an
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462"&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_509_+=d_lkno;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662"&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_507no_+=d_lkno;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_507co_+=d_lkco;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_503co_+=d_lkco;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_503no_+=d_lkno;
							d_503_=d_503co_-d_503no_;
							d_507_=d_507no_-d_507co_;
						}
					}
					else 
					if(s_lkmang.Trim()=="0218")
					{
						if(s_lktkno.Trim()!="" || s_lktkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_609+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66121"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_607no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66111") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66121")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_607co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46111") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_603co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_603no+=d_lkno;
							d_603=d_603co-d_603no;
							d_607=d_607no-d_607co;

							//hoat dong khong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_619+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66122"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_617no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66112") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66122")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_617co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46112") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_613co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_613no+=d_lkno;
							d_613=d_613co-d_613no;
							d_617=d_617no-d_617co;

							//du an
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462"&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_609_+=d_lkno;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662"&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_607no_+=d_lkno;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_607co_+=d_lkco;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_603co_+=d_lkco;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_603no_+=d_lkno;
							d_603_=d_603co_-d_603no_;
							d_607_=d_607no_-d_607co_;
						}
					}
					else
						if(s_lkmang.Trim()=="0401")
					{
						if(s_lktkno.Trim()!="" || s_lktkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_809+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66121"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_807no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66111") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66121")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_807co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46111") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_803co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_803no+=d_lkno;
							d_803=d_803co-d_803no;
							d_807=d_807no-d_807co;

							//hoat dong khong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_819+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66122"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_817no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66112") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66122")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_817co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46112") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_813co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_813no+=d_lkno;
							d_813=d_813co-d_813no;
							d_817=d_817no-d_817co;

							//du an
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462"&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_809_+=d_lkno;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662"&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_807no_+=d_lkno;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_807co_+=d_lkco;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_803co_+=d_lkco;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_803no_+=d_lkno;
							d_803_=d_803co_-d_803no_;
							d_807_=d_807no_-d_807co_;
						}
					}
					else
						if(s_lkmang.Trim()=="0501")
					{
						if(s_lktkno.Trim()!="" || s_lktkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_909+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66121"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_907no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66111") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66121")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_907co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46111") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_903co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_903no+=d_lkno;
							d_903=d_903co-d_903no;
							d_907=d_907no-d_907co;

							//hoat dong khong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_919+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66122"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_917no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66112") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66122")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_917co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46112") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_913co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_913no+=d_lkno;
							d_913=d_913co-d_913no;
							d_917=d_917no-d_917co;

							//du an
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462"&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_909_+=d_lkno;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662"&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_907no_+=d_lkno;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_907co_+=d_lkco;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_903co_+=d_lkco;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_903no_+=d_lkno;
							d_903_=d_903co_-d_903no_;
							d_907_=d_907no_-d_907co_;
						}
					}
					else
						if(s_lkmang.Trim()=="0402")
					{
						if(s_lktkno.Trim()!="" || s_lktkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_1009+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66121"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1007no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66111") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66121")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1007co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46111") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_1003co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_1003no+=d_lkno;
							d_1003=d_1003co-d_1003no;
							d_1007=d_1007no-d_1007co;

							//hoat dong khong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_1019+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66122"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1017no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66112") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66122")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1017co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46112") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_1013co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_1013no+=d_lkno;
							d_1013=d_1013co-d_1013no;
							d_1017=d_1017no-d_1017co;

							//du an
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462"&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_1009_+=d_lkno;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662"&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1007no_+=d_lkno;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1007co_+=d_lkco;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_1003co_+=d_lkco;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_1003no_+=d_lkno;
							d_1003_=d_1003co_-d_603no_;
							d_1007_=d_1007no_-d_1007co_;
						}
					}
					else
						if(s_lkmang.Trim()=="0502")
					{
						if(s_lktkno.Trim()!="" || s_lktkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_1109+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66121"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1107no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66111") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66121")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1107co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46111") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_1103co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_1103no+=d_lkno;
							d_1103=d_1103co-d_1103no;
							d_1107=d_1107no-d_1107co;

							//hoat dong khong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_1119+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66122"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1117no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66112") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66122")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1117co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46112") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_1113co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_1113no+=d_lkno;
							d_1113=d_1113co-d_1113no;
							d_1117=d_1117no-d_1117co;

							//du an
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462"&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_1109_+=d_lkno;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662"&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1107no_+=d_lkno;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1107co_+=d_lkco;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_1103co_+=d_lkco;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_1103no_+=d_lkno;
							d_1103_=d_1103co_-d_1103no_;
							d_1107_=d_1107no_-d_1107co_;
						}
					}
					#endregion 

					if(((s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462")|| (s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662"))
						|| ((s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462")|| (s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662")))
						ds_Data3.Tables[0].Rows[j]["phanloai"]="II";
					else
						if(((s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="461")|| (s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="661"))
						|| ((s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="461")|| (s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="661")))
						ds_Data3.Tables[0].Rows[j]["phanloai"]="I";
					#region add them row vao table
					//hoat dong
					ds_Data3.Tables[0].Rows[j]["d303"]=d_303;
					ds_Data3.Tables[0].Rows[j]["d307"]=d_307;
					ds_Data3.Tables[0].Rows[j]["d309"]=d_309;

					ds_Data3.Tables[0].Rows[j]["d313"]=d_313;
					ds_Data3.Tables[0].Rows[j]["d317"]=d_317;
					ds_Data3.Tables[0].Rows[j]["d319"]=d_319;

					ds_Data3.Tables[0].Rows[j]["d403"]=d_403;
					ds_Data3.Tables[0].Rows[j]["d407"]=d_407;
					ds_Data3.Tables[0].Rows[j]["d409"]=d_409;

					ds_Data3.Tables[0].Rows[j]["d413"]=d_413;
					ds_Data3.Tables[0].Rows[j]["d417"]=d_417;
					ds_Data3.Tables[0].Rows[j]["d419"]=d_419;

					ds_Data3.Tables[0].Rows[j]["d503"]=d_503;
					ds_Data3.Tables[0].Rows[j]["d507"]=d_507;
					ds_Data3.Tables[0].Rows[j]["d509"]=d_509;

					ds_Data3.Tables[0].Rows[j]["d513"]=d_513;
					ds_Data3.Tables[0].Rows[j]["d517"]=d_517;
					ds_Data3.Tables[0].Rows[j]["d519"]=d_519;

					ds_Data3.Tables[0].Rows[j]["d603"]=d_603;
					ds_Data3.Tables[0].Rows[j]["d607"]=d_607;
					ds_Data3.Tables[0].Rows[j]["d609"]=d_609;

					ds_Data3.Tables[0].Rows[j]["d613"]=d_613;
					ds_Data3.Tables[0].Rows[j]["d617"]=d_617;
					ds_Data3.Tables[0].Rows[j]["d619"]=d_619;

					ds_Data3.Tables[0].Rows[j]["d803"]=d_303;
					ds_Data3.Tables[0].Rows[j]["d807"]=d_307;
					ds_Data3.Tables[0].Rows[j]["d809"]=d_309;

					ds_Data3.Tables[0].Rows[j]["d813"]=d_313;
					ds_Data3.Tables[0].Rows[j]["d817"]=d_317;
					ds_Data3.Tables[0].Rows[j]["d819"]=d_319;

					ds_Data3.Tables[0].Rows[j]["d903"]=d_303;
					ds_Data3.Tables[0].Rows[j]["d907"]=d_307;
					ds_Data3.Tables[0].Rows[j]["d909"]=d_309;

					ds_Data3.Tables[0].Rows[j]["d913"]=d_313;
					ds_Data3.Tables[0].Rows[j]["d917"]=d_317;
					ds_Data3.Tables[0].Rows[j]["d919"]=d_319;

					ds_Data3.Tables[0].Rows[j]["d1003"]=d_303;
					ds_Data3.Tables[0].Rows[j]["d1007"]=d_307;
					ds_Data3.Tables[0].Rows[j]["d1009"]=d_309;

					ds_Data3.Tables[0].Rows[j]["d1013"]=d_313;
					ds_Data3.Tables[0].Rows[j]["d1017"]=d_317;
					ds_Data3.Tables[0].Rows[j]["d1019"]=d_319;

					ds_Data3.Tables[0].Rows[j]["d1103"]=d_303;
					ds_Data3.Tables[0].Rows[j]["d1107"]=d_307;
					ds_Data3.Tables[0].Rows[j]["d1109"]=d_309;

					ds_Data3.Tables[0].Rows[j]["d1113"]=d_313;
					ds_Data3.Tables[0].Rows[j]["d1117"]=d_317;
					ds_Data3.Tables[0].Rows[j]["d1119"]=d_319;

					//du an
					ds_Data3.Tables[0].Rows[j]["d303_"]=d_303_;
					ds_Data3.Tables[0].Rows[j]["d307_"]=d_307_;
					ds_Data3.Tables[0].Rows[j]["d309_"]=d_309_;

					ds_Data3.Tables[0].Rows[j]["d403_"]=d_403_;
					ds_Data3.Tables[0].Rows[j]["d407_"]=d_407_;
					ds_Data3.Tables[0].Rows[j]["d409_"]=d_409_;

					ds_Data3.Tables[0].Rows[j]["d503_"]=d_503_;
					ds_Data3.Tables[0].Rows[j]["d507_"]=d_507_;
					ds_Data3.Tables[0].Rows[j]["d509_"]=d_509_;

					ds_Data3.Tables[0].Rows[j]["d603_"]=d_603_;
					ds_Data3.Tables[0].Rows[j]["d607_"]=d_607_;
					ds_Data3.Tables[0].Rows[j]["d609_"]=d_609_;

					ds_Data3.Tables[0].Rows[j]["d803_"]=d_303_;
					ds_Data3.Tables[0].Rows[j]["d807_"]=d_307_;
					ds_Data3.Tables[0].Rows[j]["d809_"]=d_309_;

					ds_Data3.Tables[0].Rows[j]["d903_"]=d_303_;
					ds_Data3.Tables[0].Rows[j]["d907_"]=d_307_;
					ds_Data3.Tables[0].Rows[j]["d909_"]=d_309_;

					ds_Data3.Tables[0].Rows[j]["d1003_"]=d_303_;
					ds_Data3.Tables[0].Rows[j]["d1007_"]=d_307_;
					ds_Data3.Tables[0].Rows[j]["d1009_"]=d_309_;

					ds_Data3.Tables[0].Rows[j]["d1103_"]=d_303_;
					ds_Data3.Tables[0].Rows[j]["d1107_"]=d_307_;
					ds_Data3.Tables[0].Rows[j]["d1109_"]=d_309_;
					#endregion
				}
			}
			
			if(ds_Data3!=null)
				ds_Data.Merge(ds_Data3);
			ds_Data.AcceptChanges();
			try
			{
				if(flag_dsnull)return null;
				else 
					ds_Data.WriteXml("..\\xml\\KT_mKPI.xml",XmlWriteMode.WriteSchema);
			}
			catch{}
			return ds_Data;
		}
		
		private string _trangfsmKPI(LibKetoan.AccessData a,string s_IDlk,string s_mm, string s_mm1, string s_yy, string s_yyyy, string s_IDChuong,  string s_IDHoatDong, string s_IDMuc, string s_IDNhombc, string s_IDNguon)
		{
			sql=" select lk.lk as lk, substr(trim(lk.lk),0,3) as loai,hoatdong,";
			sql+=" substr(trim(lk.lk),5,3) as khoan,";
			sql+=" case when (tkno.stk like '461%' or tkno.stk like '661%' or tkno.stk like '462%' or tkno.stk like '662%') then ctct.stien else 0 end as no,";
			sql+=" case when (tkco.stk like '461%' or tkco.stk like '661%' or tkco.stk like '462%' or tkco.stk like '662%') then ctct.stien else 0 end as co,";
			sql+=" tkno.stk as tkno,tkco.stk as tkco,ng.mang,nv.id as idnghiepvu,nv.ten as tennghiepvu,";
		
			sql+=" 0 as d302, 0 as d306, 0 as d308, 0 as d402, 0 as d406,0 as d408,";
			sql+=" 0 as d502, 0 as d506, 0 as d508, 0 as d602, 0 as d606,0 as d608,";
			sql+=" 0 as d702, 0 as d706, 0 as d708, 0 as d802, 0 as d806,0 as d808,";
			sql+=" 0 as d902, 0 as d906, 0 as d908, 0 as d1102, 0 as d1106,0 as d1108,";
			sql+=" 0 as d1202, 0 as d1206, 0 as d1208, 0 as d1302, 0 as d1306,0 as d1308,";
			sql+=" 0 as d1402, 0 as d1406, 0 as d1408,";

			sql+=" 0 as d312, 0 as d316, 0 as d318, 0 as d412, 0 as d416,0 as d418,";
			sql+=" 0 as d512, 0 as d516, 0 as d518, 0 as d612, 0 as d616,0 as d618,";
			sql+=" 0 as d712, 0 as d716, 0 as d718, 0 as d812, 0 as d816,0 as d818,";
			sql+=" 0 as d912, 0 as d916, 0 as d918, 0 as d1112, 0 as d1116,0 as d1118,";
			sql+=" 0 as d1212, 0 as d1216, 0 as d1218, 0 as d1312, 0 as d1316,0 as d1318,";
			sql+=" 0 as d1412, 0 as d1416, 0 as d1418,";

			sql+=" 0 as d302_, 0 as d306_, 0 as d308_, 0 as d402_, 0 as d406_,0 as d408_,";
			sql+=" 0 as d502_, 0 as d506_, 0 as d508_, 0 as d602_, 0 as d606_,0 as d608_,";
			sql+=" 0 as d702_, 0 as d706_, 0 as d708_, 0 as d802_, 0 as d806_,0 as d808_,";
			sql+=" 0 as d902_, 0 as d906_, 0 as d908_, 0 as d1102_, 0 as d1106_,0 as d1108_,";
			sql+=" 0 as d1202_, 0 as d1206_, 0 as d1208_, 0 as d1302_, 0 as d1306_,0 as d1308_,";
			sql+=" 0 as d1402_, 0 as d1406_, 0 as d1408_,";
			

			sql+=" 0 as d301, 0 as d311, 0 as d301_,";
			sql+=" 0 as d401, 0 as d411, 0 as d401_,";
			sql+=" 0 as d501, 0 as d511, 0 as d501_,";
			sql+=" 0 as d601, 0 as d611, 0 as d601_,";
			sql+=" 0 as d701, 0 as d711, 0 as d701_,";
			sql+=" 0 as d801, 0 as d811, 0 as d801_,";
			sql+=" 0 as d901, 0 as d911, 0 as d901_,";		
			sql+=" 0 as d1101, 0 as d1111, 0 as d1101_,";
			sql+=" 0 as d1201, 0 as d1211, 0 as d1201_,";
			sql+=" 0 as d1301, 0 as d1311, 0 as d1301_,";
			sql+=" 0 as d1401, 0 as d1411, 0 as d1401_,";

			sql+=" 0 as d303, 0 as d307, 0 as d309, 0 as d403, 0 as d407,0 as d409,";
			sql+=" 0 as d503, 0 as d507, 0 as d509, 0 as d603, 0 as d607,0 as d609,";
			sql+=" 0 as d703, 0 as d707, 0 as d709, 0 as d803, 0 as d807,0 as d809,";
			sql+=" 0 as d903, 0 as d907, 0 as d909, 0 as d1103, 0 as d1107,0 as d1109,";
			sql+=" 0 as d1203, 0 as d1207, 0 as d1209, 0 as d1303, 0 as d1307,0 as d1309,";
			sql+=" 0 as d1403, 0 as d1407, 0 as d1409,";

			sql+=" 0 as d313, 0 as d317, 0 as d319, 0 as d413, 0 as d417,0 as d419,";
			sql+=" 0 as d513, 0 as d517, 0 as d519, 0 as d613, 0 as d617,0 as d619,";
			sql+=" 0 as d713, 0 as d717, 0 as d719, 0 as d813, 0 as d817,0 as d819,";
			sql+=" 0 as d913, 0 as d917, 0 as d919, 0 as d1113, 0 as d1117,0 as d1119,";
			sql+=" 0 as d1213, 0 as d1217, 0 as d1219, 0 as d1313, 0 as d1317,0 as d1319,";
			sql+=" 0 as d1413, 0 as d1417, 0 as d1419,";

			sql+=" 0 as d303_, 0 as d307_, 0 as d309_, 0 as d403_, 0 as d407_,0 as d409_,";
			sql+=" 0 as d503_, 0 as d507_, 0 as d509_, 0 as d603_, 0 as d607_,0 as d609_,";
			sql+=" 0 as d703_, 0 as d707_, 0 as d709_, 0 as d803_, 0 as d807_,0 as d809_,";
			sql+=" 0 as d903_, 0 as d907_, 0 as d909_, 0 as d1103_, 0 as d1107_,0 as d1109_,";
			sql+=" 0 as d1203_, 0 as d1207_, 0 as d1209_, 0 as d1303_, 0 as d1307_,0 as d1309_,";
			sql+=" 0 as d1403_, 0 as d1407_, 0 as d1409_,";

			sql+=" '0' as phanloai";
			sql+=" from "+a.user+".a_ct"+s_yy+" ct inner join "+a.user+".a_ctct"+s_yy+" ctct on ct.id=ctct.idct";
			sql+=" inner join "+a.user+".a_dmlk lk on ctct.lk=lk.id";
			sql+=" inner join "+a.user+".a_dmtk tkno on ct.tknoa=tkno.id";
			sql+=" inner join "+a.user+".a_dmtk tkco on ct.tkcoa=tkco.id";
			sql+=" inner join "+a.user+".a_dmng ng on (substr(trim(tkno.stk),6,length(trim(tkno.stk))) =ng.mang or ";
			sql+=" substr(trim(tkno.stk),7,length(trim(tkno.stk)))=ng.mang or";
			sql+=" substr(trim(tkco.stk),6,length(trim(tkco.stk))) =ng.mang or ";
			sql+=" substr(trim(tkco.stk),7,length(trim(tkco.stk)))=ng.mang)";
			sql+=" left join "+a.user+".a_nghiepvu nv on ct.nghiepvu=nv.id";
			sql+=" where (tkno.stk like '461%' or tkno.stk like '462' or tkno.stk like '661' or tkno.stk like '662%' ";
			sql+=" or tkco.stk like '461%' or tkco.stk like '462' or tkco.stk like '661' or tkco.stk like '662%')";
			if(s_IDNguon!="")sql+=" and ng.id="+s_IDNguon+"";
			if(s_IDlk!="")sql+=" and ctct.lk=" + s_IDlk+"";

			if (s_mm !="" || s_mm1!="")
				sql += " AND ct.thanggs BETWEEN "+ s_mm + " AND " + s_mm1;		
			if(s_IDMuc!="")sql+= " and ch.mtm like '" + s_IDMuc+"%'";
			if(s_IDChuong!="")sql+=" and ct.chuong="+s_IDChuong;
			if(s_IDHoatDong!="")sql+=" and ct.hoatdong="+s_IDHoatDong;			
			if(s_IDNhombc!="")sql+=" and ct.idbc="+s_IDNhombc;
			return sql;
		}

		#region do_du_lieu_trangfsmKPI_la
		public DataSet _trangfsmKPI_la(LibKetoan.AccessData a,string s_IDlk,string s_mm, string s_mm1, string s_yy, string s_yyyy, string s_IDChuong,  string s_IDHoatDong, string s_IDMuc, string s_IDNhombc, string s_IDNguon)
		{
			//tinh fat sinh
			sql=_trangfsmKPI(a,s_IDlk,s_mm,s_mm1,s_yy,s_yyyy,s_IDChuong,s_IDHoatDong,s_IDMuc,s_IDNhombc,s_IDNguon);
			//duyet toan danh sach, do du lieu vao cot thich hop
			ds_Data=a.get_data(sql);
			if(ds_Data!=null && ds_Data.Tables[0].Rows.Count>0)
			{
				int i_countfs=ds_Data.Tables[0].Rows.Count-1;
				string s_mang="",s_tkno="",s_tkco="",s_ngvu="";
				decimal d_no=0,d_co=0;
				#region//khai bao bien 
				//hoat dong thuong xuyen				
				decimal d_302=0,d_302no=0,d_302co=0,d_306=0,d_306no=0,d_306co=0,d_308=0;
				decimal d_402=0,d_402no=0,d_402co=0,d_406=0,d_406no=0,d_406co=0,d_408=0;
				decimal d_502=0,d_502no=0,d_502co=0,d_506=0,d_506no=0,d_506co=0,d_508=0;
				decimal d_602=0,d_602no=0,d_602co=0,d_606=0,d_606no=0,d_606co=0,d_608=0;
				decimal d_702=0,d_702no=0,d_702co=0,d_706=0,d_706no=0,d_706co=0,d_708=0;
				decimal d_802=0,d_802no=0,d_802co=0,d_806=0,d_806no=0,d_806co=0,d_808=0;
				decimal d_902=0,d_902no=0,d_902co=0,d_906=0,d_906no=0,d_906co=0,d_908=0;				
				decimal d_1102=0,d_1102no=0,d_1102co=0,d_1106=0,d_1106no=0,d_1106co=0,d_1108=0;
				decimal d_1202=0,d_1202no=0,d_1202co=0,d_1206=0,d_1206no=0,d_1206co=0,d_1208=0;
				decimal d_1302=0,d_1302no=0,d_1302co=0,d_1306=0,d_1306no=0,d_1306co=0,d_1308=0;
				decimal d_1402=0,d_1402no=0,d_1402co=0,d_1406=0,d_1406no=0,d_1406co=0,d_1408=0;

				//khai bao bien du an 				
				decimal d_302_=0,d_302no_=0,d_302co_=0,d_306_=0,d_306no_=0,d_306co_=0,d_308_=0;
				decimal d_402_=0,d_402no_=0,d_402co_=0,d_406_=0,d_406no_=0,d_406co_=0,d_408_=0;
				decimal d_502_=0,d_502no_=0,d_502co_=0,d_506_=0,d_506no_=0,d_506co_=0,d_508_=0;
				decimal d_602_=0,d_602no_=0,d_602co_=0,d_606_=0,d_606no_=0,d_606co_=0,d_608_=0;
				decimal d_702_=0,d_702no_=0,d_702co_=0,d_706_=0,d_706no_=0,d_706co_=0,d_708_=0;
				decimal d_802_=0,d_802no_=0,d_802co_=0,d_806_=0,d_806no_=0,d_806co_=0,d_808_=0;
				decimal d_902_=0,d_902no_=0,d_902co_=0,d_906_=0,d_906no_=0,d_906co_=0,d_908_=0;				
				decimal d_1102_=0,d_1102no_=0,d_1102co_=0,d_1106_=0,d_1106no_=0,d_1106co_=0,d_1108_=0;
				decimal d_1202_=0,d_1202no_=0,d_1202co_=0,d_1206_=0,d_1206no_=0,d_1206co_=0,d_1208_=0;
				decimal d_1302_=0,d_1302no_=0,d_1302co_=0,d_1306_=0,d_1306no_=0,d_1306co_=0,d_1308_=0;
				decimal d_1402_=0,d_1402no_=0,d_1402co_=0,d_1406_=0,d_1406no_=0,d_1406co_=0,d_1408_=0;

				//khai bao bien hoat dong khong thuong xuyen			
				decimal d_312=0,d_312no=0,d_312co=0,d_316=0,d_316no=0,d_316co=0,d_318=0;
				decimal d_412=0,d_412no=0,d_412co=0,d_416=0,d_416no=0,d_416co=0,d_418=0;
				decimal d_512=0,d_512no=0,d_512co=0,d_516=0,d_516no=0,d_516co=0,d_518=0;
				decimal d_612=0,d_612no=0,d_612co=0,d_616=0,d_616no=0,d_616co=0,d_618=0;
				decimal d_712=0,d_712no=0,d_712co=0,d_716=0,d_716no=0,d_716co=0,d_718=0;
				decimal d_812=0,d_812no=0,d_812co=0,d_816=0,d_816no=0,d_816co=0,d_818=0;
				decimal d_912=0,d_912no=0,d_912co=0,d_916=0,d_916no=0,d_916co=0,d_918=0;
				decimal d_1112=0,d_1112no=0,d_1112co=0,d_1116=0,d_1116no=0,d_1116co=0,d_1118=0;
				decimal d_1212=0,d_1212no=0,d_1212co=0,d_1216=0,d_1216no=0,d_1216co=0,d_1218=0;
				decimal d_1312=0,d_1312no=0,d_1312co=0,d_1316=0,d_1316no=0,d_1316co=0,d_1318=0;
				decimal d_1412=0,d_1412no=0,d_1412co=0,d_1416=0,d_1416no=0,d_1416co=0,d_1418=0;
				#endregion 
				
				for(int i=0;i<=i_countfs;i++)
				{
					//khoi tao lai gia tri bang 0
					#region khoi tao gia tri cho bien
					//hoat dong thuong xuyen
					d_302=0;d_302no=0;d_302co=0;d_306=0;d_306no=0;d_306co=0;d_308=0;
					d_402=0;d_402no=0;d_402co=0;d_406=0;d_406no=0;d_406co=0;d_408=0;
					d_502=0;d_502no=0;d_502co=0;d_506=0;d_506no=0;d_506co=0;d_508=0;
					d_602=0;d_602no=0;d_602co=0;d_606=0;d_606no=0;d_606co=0;d_608=0;
					d_702=0;d_702no=0;d_702co=0;d_706=0;d_706no=0;d_706co=0;d_708=0;
					d_802=0;d_802no=0;d_802co=0;d_806=0;d_806no=0;d_806co=0;d_808=0;
					d_902=0;d_902no=0;d_902co=0;d_906=0;d_906no=0;d_906co=0;d_908=0;					
					d_1102=0;d_1102no=0;d_1102co=0;d_1106=0;d_1106no=0;d_1106co=0;d_1108=0;
					d_1202=0;d_1202no=0;d_1202co=0;d_1206=0;d_1206no=0;d_1206co=0;d_1208=0;
					d_1302=0;d_1302no=0;d_1302co=0;d_1306=0;d_1306no=0;d_1306co=0;d_1308=0;
					d_1402=0;d_1402no=0;d_1402co=0;d_1406=0;d_1406no=0;d_1406co=0;d_1408=0;
					
					//du an 
					d_302_=0;d_302no_=0;d_302co_=0;d_306_=0;d_306no_=0;d_306co_=0;d_308_=0;
					d_402_=0;d_402no_=0;d_402co_=0;d_406_=0;d_406no_=0;d_406co_=0;d_408_=0;
					d_502_=0;d_502no_=0;d_502co_=0;d_506_=0;d_506no_=0;d_506co_=0;d_508_=0;
					d_602_=0;d_602no_=0;d_602co_=0;d_606_=0;d_606no_=0;d_606co_=0;d_608_=0;
					d_702_=0;d_702no_=0;d_702co_=0;d_706_=0;d_706no_=0;d_706co_=0;d_708_=0;
					d_802_=0;d_802no_=0;d_802co_=0;d_806_=0;d_806no_=0;d_806co_=0;d_808_=0;
					d_902_=0;d_902no_=0;d_902co_=0;d_906_=0;d_906no_=0;d_906co_=0;d_908_=0;					
					d_1102_=0;d_1102no_=0;d_1102co_=0;d_1106_=0;d_1106no_=0;d_1106co_=0;d_1108_=0;
					d_1202_=0;d_1202no_=0;d_1202co_=0;d_1206_=0;d_1206no_=0;d_1206co_=0;d_1208_=0;
					d_1302_=0;d_1302no_=0;d_1302co_=0;d_1306_=0;d_1306no_=0;d_1306co_=0;d_1308_=0;
					d_1402_=0;d_1402no_=0;d_1402co_=0;d_1406_=0;d_1406no_=0;d_1406co_=0;d_1408_=0;

					//hoat dong khong thuong xuyen
					d_312=0;d_312no=0;d_312co=0;d_316=0;d_316no=0;d_316co=0;d_318=0;
					d_412=0;d_412no=0;d_412co=0;d_416=0;d_416no=0;d_416co=0;d_418=0;
					d_512=0;d_512no=0;d_512co=0;d_516=0;d_516no=0;d_516co=0;d_518=0;
					d_612=0;d_612no=0;d_612co=0;d_616=0;d_616no=0;d_616co=0;d_618=0;
					d_712=0;d_712no=0;d_712co=0;d_716=0;d_716no=0;d_716co=0;d_718=0;
					d_812=0;d_812no=0;d_812co=0;d_816=0;d_816no=0;d_816co=0;d_818=0;
					d_912=0;d_912no=0;d_912co=0;d_916=0;d_916no=0;d_916co=0;d_918=0;					
					d_1112=0;d_1112no=0;d_1112co=0;d_1116=0;d_1116no=0;d_1116co=0;d_1118=0;
					d_1212=0;d_1212no=0;d_1212co=0;d_1216=0;d_1216no=0;d_1216co=0;d_1218=0;
					d_1312=0;d_1312no=0;d_1312co=0;d_1316=0;d_1316no=0;d_1316co=0;d_1318=0;
					d_1412=0;d_1412no=0;d_1412co=0;d_1416=0;d_1416no=0;d_1416co=0;d_1418=0;
					#endregion 

					//khoi tao gia tri cho cac bien
					s_ngvu=ds_Data.Tables[0].Rows[i]["idnghiepvu"].ToString();
					s_mang=ds_Data.Tables[0].Rows[i]["mang"].ToString();
					s_tkno=ds_Data.Tables[0].Rows[i]["tkno"].ToString();
					s_tkco=ds_Data.Tables[0].Rows[i]["tkco"].ToString();
					d_no=Convert.ToDecimal(ds_Data.Tables[0].Rows[i]["no"].ToString());
					d_co=Convert.ToDecimal(ds_Data.Tables[0].Rows[i]["co"].ToString());
					#region kiem tra ma nguon do so lieu fat sinh vao ds
					//kiem tra dk, do so lieu
					if(s_mang.Trim()=="0113" )
					{
						if(s_tkno.Trim()!="" || s_tkco.Trim()!="")
						{
							//hoat dong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_308+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66121"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_306no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66111") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66121")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_306co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46111") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_302co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_302no+=d_no;
							d_302=d_302co-d_302no;
							d_306=d_306no-d_306co;							

							//hoat dong khong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_318+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66122"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_316no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66112") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66122")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_316co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46112") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_312co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_312no+=d_no;
							d_312=d_312co-d_312no;
							d_316=d_316no-d_316co;

							//du an 
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && (s_ngvu=="8" || s_ngvu=="7"))
								d_308_+=d_no;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
								d_306no_+=d_no;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
								d_306co_+=d_co;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_302co_+=d_co;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_302no_+=d_no;
							d_302_=d_302co_-d_302no_;
							d_306_=d_306no_-d_306co_;							
						}
					}
					else
						if(s_mang.Trim()=="0114")
					{
						if(s_tkno.Trim()!="" || s_tkco.Trim()!="")
						{
							//hoat dong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_408+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66121"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_406no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66111") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66121")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_406co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46111") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_402co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_402no+=d_no;
							d_402=d_402co-d_402no;
							d_406=d_406no-d_406co;

							//hoat dong khong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_418+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66122"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_416no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66112") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66122")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_416co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46112") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_412co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_412no+=d_no;
							d_412=d_412co-d_412no;
							d_416=d_416no-d_416co;

							//du an
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462"&& (s_ngvu=="8" || s_ngvu=="7"))
								d_408_+=d_no;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662"&& s_ngvu!="8"&&s_ngvu!="7")	
								d_406no_+=d_no;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
								d_406co_+=d_co;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_402co_+=d_co;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_402no_+=d_no;
							d_402_=d_402co_-d_402no_;
							d_406_=d_406no_-d_406co_;							
						}
					}
					else
						if(s_mang.Trim()=="02121")
					{
						if(s_tkno.Trim()!="" || s_tkco.Trim()!="")
						{
							//hoat dong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_508+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66121"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_506no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66111") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66121")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_506co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46111") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_502co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_502no+=d_no;
							d_502=d_502co-d_502no;
							d_506=d_506no-d_506co;

							//hoat dong khong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_518+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66122"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_516no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66112") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66122")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_516co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46112") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_512co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_512no+=d_no;
							d_512=d_512co-d_512no;
							d_516=d_516no-d_516co;

							//du an
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462"&& (s_ngvu=="8" || s_ngvu=="7"))
								d_508_+=d_no;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662"&& s_ngvu!="8"&&s_ngvu!="7")	
								d_506no_+=d_no;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
								d_506co_+=d_co;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_502co_+=d_co;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_502no_+=d_no;
							d_502_=d_502co_-d_502no_;
							d_506_=d_506no_-d_506co_;							
						}
					}
					else 					
						if(s_mang.Trim()=="02122")
					{
						if(s_tkno.Trim()!="" || s_tkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_608+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66121"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_606no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66111") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66121")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_606co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46111") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_602co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_602no+=d_no;
							d_602=d_602co-d_602no;
							d_606=d_606no-d_606co;

							//hoat dong khong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_618+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66122"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_616no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66112") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66122")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_616co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46112") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_612co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_612no+=d_no;
							d_612=d_612co-d_612no;
							d_616=d_616no-d_616co;

							//du an
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462"&& (s_ngvu=="8" || s_ngvu=="7"))
								d_608_+=d_no;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662"&& s_ngvu!="8"&&s_ngvu!="7")	
								d_606no_+=d_no;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
								d_606co_+=d_co;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_602co_+=d_co;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_602no_+=d_no;
							d_602_=d_602co_-d_602no_;
							d_606_=d_606no_-d_606co_;
						}
					}					
					else 						
						if(s_mang.Trim()=="02123")
					{
						if(s_tkno.Trim()!="" || s_tkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_708+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66121"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_706no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66111") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66121")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_706co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46111") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_702co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_702no+=d_no;
							d_702=d_702co-d_702no;
							d_706=d_706no-d_706co;

							//hoat dong khong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_718+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66122"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_716no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66112") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66122")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_716co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46112") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_712co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_712no+=d_no;
							d_712=d_712co-d_712no;
							d_716=d_716no-d_716co;

							//du an
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462"&& (s_ngvu=="8" || s_ngvu=="7"))
								d_708_+=d_no;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662"&& s_ngvu!="8"&&s_ngvu!="7")	
								d_706no_+=d_no;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
								d_706co_+=d_co;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_702co_+=d_co;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_702no_+=d_no;
							d_702_=d_702co_-d_702no_;
							d_706_=d_706no_-d_706co_;
						}
								
					}
					else 						
						if(s_mang.Trim()=="0214")
					{
						if(s_tkno.Trim()!="" || s_tkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_808+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66121"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_906no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66111") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66121")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_806co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46111") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_802co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_802no+=d_no;
							d_802=d_802co-d_802no;
							d_806=d_806no-d_806co;

							//hoat dong khong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_818+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66122"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_816no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66112") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66122")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_816co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46112") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_812co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_812no+=d_no;
							d_812=d_812co-d_812no;
							d_816=d_816no-d_816co;

							//du an
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462"&& (s_ngvu=="8" || s_ngvu=="7"))
								d_808_+=d_no;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662"&& s_ngvu!="8"&&s_ngvu!="7")	
								d_806no_+=d_no;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
								d_806co_+=d_co;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_802co_+=d_co;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_802no_+=d_no;
							d_802_=d_802co_-d_802no_;
							d_806_=d_806no_-d_806co_;
						}
								
					}
					else 
						if(s_mang.Trim()=="0218")
					{
						if(s_tkno.Trim()!="" || s_tkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_908+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66121"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_906no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66111") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66121")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_906co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46111") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_902co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_902no+=d_no;
							d_902=d_902co-d_902no;
							d_906=d_906no-d_906co;

							//hoat dong khong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_918+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66122"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_916no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66112") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66122")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_916co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46112") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_912co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_912no+=d_no;
							d_912=d_912co-d_912no;
							d_916=d_916no-d_916co;

							//du an
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462"&& (s_ngvu=="8" || s_ngvu=="7"))
								d_908_+=d_no;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662"&& s_ngvu!="8"&&s_ngvu!="7")	
								d_906no_+=d_no;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
								d_906co_+=d_co;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_902co_+=d_co;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_902no_+=d_no;
							d_902_=d_902co_-d_902no_;
							d_906_=d_906no_-d_906co_;
						}
								
					}
					else
						if(s_mang.Trim()=="0401")
					{
						if(s_tkno.Trim()!="" || s_tkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_1108+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66121"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_1106no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66111") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66121")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_1106co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46111") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_1102co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_1102no+=d_no;
							d_1102=d_1102co-d_1102no;
							d_1106=d_1106no-d_1106co;

							//hoat dong khong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_1118+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66122"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_1116no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66112") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66122")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_1116co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46112") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_1112co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_1112no+=d_no;
							d_1112=d_1112co-d_1112no;
							d_1116=d_1116no-d_1116co;

							//du an
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462"&& (s_ngvu=="8" || s_ngvu=="7"))
								d_1108_+=d_no;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662"&& s_ngvu!="8"&&s_ngvu!="7")	
								d_1106no_+=d_no;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
								d_1106co_+=d_co;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_1102co_+=d_co;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_1102no_+=d_no;
							d_1102_=d_1102co_-d_1102no_;
							d_1106_=d_1106no_-d_1106co_;
						}
								
					}
					else
						if(s_mang.Trim()=="0501")
					{
						if(s_tkno.Trim()!="" || s_tkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_1208+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66121"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_1206no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66111") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66121")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_1206co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46111") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_1202co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_1202no+=d_no;
							d_1202=d_1202co-d_1202no;
							d_1206=d_1206no-d_1206co;

							//hoat dong khong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_1218+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66122"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_1216no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66112") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66122")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_1216co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46112") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_1212co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_1212no+=d_no;
							d_1212=d_1212co-d_1212no;
							d_1216=d_1216no-d_1216co;

							//du an
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462"&& (s_ngvu=="8" || s_ngvu=="7"))
								d_1208_+=d_no;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662"&& s_ngvu!="8"&&s_ngvu!="7")	
								d_1206no_+=d_no;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
								d_1206co_+=d_co;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_1202co_+=d_co;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_1202no_+=d_no;
							d_1202_=d_1202co_-d_1202no_;
							d_1206_=d_1206no_-d_1206co_;
						}
								
					}
					else
						if(s_mang.Trim()=="0402")
					{
						if(s_tkno.Trim()!="" || s_tkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_1308+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66121"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_1306no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66111") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66121")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_1306co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46111") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_1302co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_1302no+=d_no;
							d_1302=d_1302co-d_1302no;
							d_1306=d_1306no-d_1306co;

							//hoat dong khong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_1318+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66122"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_1316no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66112") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66122")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_1316co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46112") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_1312co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_1312no+=d_no;
							d_1312=d_1312co-d_1312no;
							d_1316=d_1316no-d_1316co;

							//du an
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462"&& (s_ngvu=="8" || s_ngvu=="7"))
								d_1308_+=d_no;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662"&& s_ngvu!="8"&&s_ngvu!="7")	
								d_1306no_+=d_no;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
								d_1306co_+=d_co;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_1302co_+=d_co;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_1302no_+=d_no;
							d_1302_=d_1302co_-d_1302no_;
							d_1306_=d_1306no_-d_1306co_;
						}
								
					}
					else
						if(s_mang.Trim()=="0502")
					{
						if(s_tkno.Trim()!="" || s_tkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_1408+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66121"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_1406no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66111") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66121")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_1406co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46111") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_1402co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46111") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46121")) && s_ngvu!="8" && s_ngvu!="7")
								d_1402no+=d_no;
							d_1402=d_1402co-d_1402no;
							d_1406=d_1406no-d_1406co;

							//hoat dong khong thuong xuyen
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122"))&& (s_ngvu=="8" || s_ngvu=="7"))
								d_1418+=d_no;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="66122"))&& s_ngvu!="8"&&s_ngvu!="7")	
								d_1416no+=d_no;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66112") ||(s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="66122")) && s_ngvu!="8"&&s_ngvu!="7")	
								d_1416co+=d_co;
							if(((s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46112") || (s_tkco.Trim().Length>=5 && s_tkco.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_1412co+=d_co;
							if(((s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46112") || (s_tkno.Trim().Length>=5 && s_tkno.Trim().Substring(0,5)=="46122")) && s_ngvu!="8" && s_ngvu!="7")
								d_1412no+=d_no;
							d_1412=d_1412co-d_1412no;
							d_1416=d_1416no-d_1416co;

							//du an
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462"&& (s_ngvu=="8" || s_ngvu=="7"))
								d_1408_+=d_no;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662"&& s_ngvu!="8"&&s_ngvu!="7")	
								d_1406no_+=d_no;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662" && s_ngvu!="8"&&s_ngvu!="7")	
								d_1406co_+=d_co;
							if(s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_1402co_+=d_co;
							if(s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462" && s_ngvu!="8" && s_ngvu!="7")
								d_1402no_+=d_no;
							d_1402_=d_1402co_-d_1402no_;
							d_1406_=d_1406no_-d_1406co_;
						}
								
					}
					#endregion
					string phanloai="";
					if(((s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="462")|| (s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="662"))
						|| ((s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="462")|| (s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="662")))
					{
						ds_Data.Tables[0].Rows[i]["phanloai"]="II";
						phanloai=ds_Data.Tables[0].Rows[i]["phanloai"].ToString();
					}
					else
					{
						if(((s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="461")|| (s_tkno.Trim().Length>=3 && s_tkno.Trim().Substring(0,3)=="661"))
							|| ((s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="461")|| (s_tkco.Trim().Length>=3 && s_tkco.Trim().Substring(0,3)=="661")))
							ds_Data.Tables[0].Rows[i]["phanloai"]="I";
						phanloai=ds_Data.Tables[0].Rows[i]["phanloai"].ToString();
					}

					#region add them dong fat sinh vao ds
					//hoat dong
					ds_Data.Tables[0].Rows[i]["d302"]=d_302;
					ds_Data.Tables[0].Rows[i]["d306"]=d_306;
					ds_Data.Tables[0].Rows[i]["d308"]=d_308;

					ds_Data.Tables[0].Rows[i]["d312"]=d_312;
					ds_Data.Tables[0].Rows[i]["d316"]=d_316;
					ds_Data.Tables[0].Rows[i]["d318"]=d_318;

					ds_Data.Tables[0].Rows[i]["d402"]=d_402;
					ds_Data.Tables[0].Rows[i]["d406"]=d_406;
					ds_Data.Tables[0].Rows[i]["d408"]=d_408;

					ds_Data.Tables[0].Rows[i]["d412"]=d_412;
					ds_Data.Tables[0].Rows[i]["d416"]=d_416;
					ds_Data.Tables[0].Rows[i]["d418"]=d_418;

					ds_Data.Tables[0].Rows[i]["d502"]=d_502;
					ds_Data.Tables[0].Rows[i]["d506"]=d_506;
					ds_Data.Tables[0].Rows[i]["d508"]=d_508;

					ds_Data.Tables[0].Rows[i]["d512"]=d_512;
					ds_Data.Tables[0].Rows[i]["d516"]=d_516;
					ds_Data.Tables[0].Rows[i]["d518"]=d_518;

					ds_Data.Tables[0].Rows[i]["d602"]=d_602;
					ds_Data.Tables[0].Rows[i]["d606"]=d_606;
					ds_Data.Tables[0].Rows[i]["d608"]=d_608;

					ds_Data.Tables[0].Rows[i]["d612"]=d_612;
					ds_Data.Tables[0].Rows[i]["d616"]=d_616;
					ds_Data.Tables[0].Rows[i]["d618"]=d_618;

					ds_Data.Tables[0].Rows[i]["d702"]=d_702;
					ds_Data.Tables[0].Rows[i]["d706"]=d_706;
					ds_Data.Tables[0].Rows[i]["d708"]=d_708;

					ds_Data.Tables[0].Rows[i]["d712"]=d_712;
					ds_Data.Tables[0].Rows[i]["d716"]=d_716;
					ds_Data.Tables[0].Rows[i]["d718"]=d_718;

					
					ds_Data.Tables[0].Rows[i]["d802"]=d_802;
					ds_Data.Tables[0].Rows[i]["d806"]=d_806;
					ds_Data.Tables[0].Rows[i]["d808"]=d_808;

					ds_Data.Tables[0].Rows[i]["d812"]=d_812;
					ds_Data.Tables[0].Rows[i]["d816"]=d_816;
					ds_Data.Tables[0].Rows[i]["d818"]=d_818;

					
					ds_Data.Tables[0].Rows[i]["d902"]=d_902;
					ds_Data.Tables[0].Rows[i]["d906"]=d_906;
					ds_Data.Tables[0].Rows[i]["d908"]=d_908;

					ds_Data.Tables[0].Rows[i]["d912"]=d_912;
					ds_Data.Tables[0].Rows[i]["d916"]=d_916;
					ds_Data.Tables[0].Rows[i]["d918"]=d_918;

					
					ds_Data.Tables[0].Rows[i]["d1102"]=d_1102;
					ds_Data.Tables[0].Rows[i]["d1106"]=d_1106;
					ds_Data.Tables[0].Rows[i]["d1108"]=d_1108;

					ds_Data.Tables[0].Rows[i]["d1112"]=d_1112;
					ds_Data.Tables[0].Rows[i]["d1116"]=d_1116;
					ds_Data.Tables[0].Rows[i]["d1118"]=d_1118;

					ds_Data.Tables[0].Rows[i]["d1202"]=d_1202;
					ds_Data.Tables[0].Rows[i]["d1206"]=d_1206;
					ds_Data.Tables[0].Rows[i]["d1208"]=d_1208;

					ds_Data.Tables[0].Rows[i]["d1212"]=d_1212;
					ds_Data.Tables[0].Rows[i]["d1216"]=d_1216;
					ds_Data.Tables[0].Rows[i]["d1218"]=d_1218;

					ds_Data.Tables[0].Rows[i]["d1302"]=d_1302;
					ds_Data.Tables[0].Rows[i]["d1306"]=d_1306;
					ds_Data.Tables[0].Rows[i]["d1308"]=d_1308;

					ds_Data.Tables[0].Rows[i]["d1312"]=d_1312;
					ds_Data.Tables[0].Rows[i]["d1316"]=d_1316;
					ds_Data.Tables[0].Rows[i]["d1318"]=d_1318;

					ds_Data.Tables[0].Rows[i]["d1402"]=d_1402;
					ds_Data.Tables[0].Rows[i]["d1406"]=d_1406;
					ds_Data.Tables[0].Rows[i]["d1408"]=d_1408;

					ds_Data.Tables[0].Rows[i]["d1412"]=d_1412;
					ds_Data.Tables[0].Rows[i]["d1416"]=d_1416;
					ds_Data.Tables[0].Rows[i]["d1418"]=d_1418;
					//du an
					ds_Data.Tables[0].Rows[i]["d302_"]=d_302_;
					ds_Data.Tables[0].Rows[i]["d306_"]=d_306_;
					ds_Data.Tables[0].Rows[i]["d308_"]=d_308_;					

					ds_Data.Tables[0].Rows[i]["d402_"]=d_402_;
					ds_Data.Tables[0].Rows[i]["d406_"]=d_406_;
					ds_Data.Tables[0].Rows[i]["d408_"]=d_408_;

					ds_Data.Tables[0].Rows[i]["d502_"]=d_502_;
					ds_Data.Tables[0].Rows[i]["d506_"]=d_506_;
					ds_Data.Tables[0].Rows[i]["d508_"]=d_508_;

					ds_Data.Tables[0].Rows[i]["d602_"]=d_602_;
					ds_Data.Tables[0].Rows[i]["d606_"]=d_606_;
					ds_Data.Tables[0].Rows[i]["d608_"]=d_608_;

					ds_Data.Tables[0].Rows[i]["d702_"]=d_702_;
					ds_Data.Tables[0].Rows[i]["d706_"]=d_706_;
					ds_Data.Tables[0].Rows[i]["d708_"]=d_708_;

					ds_Data.Tables[0].Rows[i]["d802_"]=d_802_;
					ds_Data.Tables[0].Rows[i]["d806_"]=d_806_;
					ds_Data.Tables[0].Rows[i]["d808_"]=d_808_;

					ds_Data.Tables[0].Rows[i]["d902_"]=d_902_;
					ds_Data.Tables[0].Rows[i]["d906_"]=d_906_;
					ds_Data.Tables[0].Rows[i]["d908_"]=d_908_;

					ds_Data.Tables[0].Rows[i]["d1102_"]=d_1102_;
					ds_Data.Tables[0].Rows[i]["d1106_"]=d_1106_;
					ds_Data.Tables[0].Rows[i]["d1108_"]=d_1108_;

					ds_Data.Tables[0].Rows[i]["d1202_"]=d_1202_;
					ds_Data.Tables[0].Rows[i]["d1206_"]=d_1206_;
					ds_Data.Tables[0].Rows[i]["d1208_"]=d_1208_;

					ds_Data.Tables[0].Rows[i]["d1302_"]=d_1302_;
					ds_Data.Tables[0].Rows[i]["d1306_"]=d_1306_;
					ds_Data.Tables[0].Rows[i]["d1308_"]=d_1308_;

					
					ds_Data.Tables[0].Rows[i]["d1402_"]=d_1402_;
					ds_Data.Tables[0].Rows[i]["d1406_"]=d_1406_;
					ds_Data.Tables[0].Rows[i]["d1408_"]=d_1408_;

					#endregion
				}
			}	
			//			//tinh so du dau ky
			//			try
			//			{
			//				ds_Data2=a._trangtinhsodu(s_yy,s_mm,s_IDMuc,s_IDlk,s_IDChuong,s_IDHoatDong,s_IDNhombc,s_IDNguon);
			//				if(ds_Data2!=null)
			//					ds_Data.Merge(ds_Data2);
			//				ds_Data.AcceptChanges();
			//			}
			//			catch{flag_dsnull=true;};
			//tinh luyke
			sql1=_trangfsmKPI(a,s_IDlk,"01",s_mm1,s_yy,s_yyyy,s_IDChuong,s_IDHoatDong,s_IDMuc,s_IDNhombc,s_IDNguon);
			ds_Data3=a.get_data(sql1);
			if(ds_Data3!=null && ds_Data3.Tables[0].Rows.Count>0)
			{				
				int i_countlk=ds_Data3.Tables[0].Rows.Count-1;
				string s_lkmang="",s_lktkno="",s_lktkco="",s_lkngvu="";
				decimal d_lkno=0,d_lkco=0;
				#region khai bao bien cho luy ke
				//khai bao bien hoat dong thuong xuyen
				decimal d_303=0,d_303no=0,d_303co=0,d_307=0,d_307no=0,d_307co=0,d_309=0;
				decimal d_403=0,d_403no=0,d_403co=0,d_407=0,d_407no=0,d_407co=0,d_409=0;
				decimal d_503=0,d_503no=0,d_503co=0,d_507=0,d_507no=0,d_507co=0,d_509=0;
				decimal d_603=0,d_603no=0,d_603co=0,d_607=0,d_607no=0,d_607co=0,d_609=0;
				decimal d_703=0,d_703no=0,d_703co=0,d_707=0,d_707no=0,d_707co=0,d_709=0;
				decimal d_803=0,d_803no=0,d_803co=0,d_807=0,d_807no=0,d_807co=0,d_809=0;
				decimal d_903=0,d_903no=0,d_903co=0,d_907=0,d_907no=0,d_907co=0,d_909=0;		
				decimal d_1103=0,d_1103no=0,d_1103co=0,d_1107=0,d_1107no=0,d_1107co=0,d_1109=0;
				decimal d_1203=0,d_1203no=0,d_1203co=0,d_1207=0,d_1207no=0,d_1207co=0,d_1209=0;
				decimal d_1303=0,d_1303no=0,d_1303co=0,d_1307=0,d_1307no=0,d_1307co=0,d_1309=0;
				decimal d_1403=0,d_1403no=0,d_1403co=0,d_1407=0,d_1407no=0,d_1407co=0,d_1409=0;

				//khai bao bien du an
				decimal d_303_=0,d_303no_=0,d_303co_=0,d_307_=0,d_307no_=0,d_307co_=0,d_309_=0;
				decimal d_403_=0,d_403no_=0,d_403co_=0,d_407_=0,d_407no_=0,d_407co_=0,d_409_=0;
				decimal d_503_=0,d_503no_=0,d_503co_=0,d_507_=0,d_507no_=0,d_507co_=0,d_509_=0;
				decimal d_603_=0,d_603no_=0,d_603co_=0,d_607_=0,d_607no_=0,d_607co_=0,d_609_=0;
				decimal d_703_=0,d_703no_=0,d_703co_=0,d_707_=0,d_707no_=0,d_707co_=0,d_709_=0;
				decimal d_803_=0,d_803no_=0,d_803co_=0,d_807_=0,d_807no_=0,d_807co_=0,d_809_=0;
				decimal d_903_=0,d_903no_=0,d_903co_=0,d_907_=0,d_907no_=0,d_907co_=0,d_909_=0;		
				decimal d_1103_=0,d_1103no_=0,d_1103co_=0,d_1107_=0,d_1107no_=0,d_1107co_=0,d_1109_=0;
				decimal d_1203_=0,d_1203no_=0,d_1203co_=0,d_1207_=0,d_1207no_=0,d_1207co_=0,d_1209_=0;
				decimal d_1303_=0,d_1303no_=0,d_1303co_=0,d_1307_=0,d_1307no_=0,d_1307co_=0,d_1309_=0;
				decimal d_1403_=0,d_1403no_=0,d_1403co_=0,d_1407_=0,d_1407no_=0,d_1407co_=0,d_1409_=0;


				//khai bao bien hoat dong khong thuong xuyen
				decimal d_313=0,d_313no=0,d_313co=0,d_317=0,d_317no=0,d_317co=0,d_319=0;
				decimal d_413=0,d_413no=0,d_413co=0,d_417=0,d_417no=0,d_417co=0,d_419=0;
				decimal d_513=0,d_513no=0,d_513co=0,d_517=0,d_517no=0,d_517co=0,d_519=0;
				decimal d_613=0,d_613no=0,d_613co=0,d_617=0,d_617no=0,d_617co=0,d_619=0;
				decimal d_713=0,d_713no=0,d_713co=0,d_717=0,d_717no=0,d_717co=0,d_719=0;
				decimal d_813=0,d_813no=0,d_813co=0,d_817=0,d_817no=0,d_817co=0,d_819=0;
				decimal d_913=0,d_913no=0,d_913co=0,d_917=0,d_917no=0,d_917co=0,d_919=0;		
				decimal d_1113=0,d_1113no=0,d_1113co=0,d_1117=0,d_1117no=0,d_1117co=0,d_1119=0;
				decimal d_1213=0,d_1213no=0,d_1213co=0,d_1217=0,d_1217no=0,d_1217co=0,d_1219=0;
				decimal d_1313=0,d_1313no=0,d_1313co=0,d_1317=0,d_1317no=0,d_1317co=0,d_1319=0;
				decimal d_1413=0,d_1413no=0,d_1413co=0,d_1417=0,d_1417no=0,d_1417co=0,d_1419=0;
				#endregion
				
				for(int j=0;j<=i_countlk;j++)
				{
					#region khoi tao gia tri cho bien
					//khoi tao lai gia tri bang 0
					//hoat dong thuong xuyen
					d_303=0;d_303no=0;d_303co=0;d_307=0;d_307no=0;d_307co=0;d_309=0;
					d_403=0;d_403no=0;d_403co=0;d_407=0;d_407no=0;d_407co=0;d_409=0;
					d_503=0;d_503no=0;d_503co=0;d_507=0;d_507no=0;d_507co=0;d_509=0;
					d_603=0;d_603no=0;d_603co=0;d_607=0;d_607no=0;d_607co=0;d_609=0;
					d_703=0;d_703no=0;d_703co=0;d_707=0;d_707no=0;d_707co=0;d_709=0;
					d_803=0;d_803no=0;d_803co=0;d_807=0;d_807no=0;d_807co=0;d_809=0;
					d_903=0;d_903no=0;d_903co=0;d_907=0;d_907no=0;d_907co=0;d_909=0;				
					d_1103=0;d_1103no=0;d_1103co=0;d_1107=0;d_1107no=0;d_1107co=0;d_1109=0;
					d_1203=0;d_1203no=0;d_1203co=0;d_1207=0;d_1207no=0;d_1207co=0;d_1209=0;
					d_1303=0;d_1303no=0;d_1303co=0;d_1307=0;d_1307no=0;d_1307co=0;d_1309=0;
					d_1403=0;d_1403no=0;d_1403co=0;d_1407=0;d_1407no=0;d_1407co=0;d_1409=0;
				
					//du an
					d_303_=0;d_303no_=0;d_303co_=0;d_307_=0;d_307no_=0;d_307co_=0;d_309_=0;
					d_403_=0;d_403no_=0;d_403co_=0;d_407_=0;d_407no_=0;d_407co_=0;d_409_=0;
					d_503_=0;d_503no_=0;d_503co_=0;d_507_=0;d_507no_=0;d_507co_=0;d_509_=0;
					d_603_=0;d_603no_=0;d_603co_=0;d_607_=0;d_607no_=0;d_607co_=0;d_609_=0;
					d_703_=0;d_703no_=0;d_703co_=0;d_707_=0;d_707no_=0;d_707co_=0;d_709_=0;
					d_803_=0;d_803no_=0;d_803co_=0;d_807_=0;d_807no_=0;d_807co_=0;d_809_=0;
					d_903_=0;d_903no_=0;d_903co_=0;d_907_=0;d_907no_=0;d_907co_=0;d_909_=0;				
					d_1103_=0;d_1103no_=0;d_1103co_=0;d_1107_=0;d_1107no_=0;d_1107co_=0;d_1109_=0;
					d_1203_=0;d_1203no_=0;d_1203co_=0;d_1207_=0;d_1207no_=0;d_1207co_=0;d_1209_=0;
					d_1303_=0;d_1303no_=0;d_1303co_=0;d_1307_=0;d_1307no_=0;d_1307co_=0;d_1309_=0;
					d_1403_=0;d_1403no_=0;d_1403co_=0;d_1407_=0;d_1407no_=0;d_1407co_=0;d_1409_=0;
					//hoat dong khong thuong xuyen
					d_313=0;d_313no=0;d_313co=0;d_317=0;d_317no=0;d_317co=0;d_319=0;
					d_413=0;d_413no=0;d_413co=0;d_417=0;d_417no=0;d_417co=0;d_419=0;
					d_513=0;d_513no=0;d_513co=0;d_517=0;d_517no=0;d_517co=0;d_519=0;
					d_613=0;d_613no=0;d_613co=0;d_617=0;d_617no=0;d_617co=0;d_619=0;
					d_713=0;d_713no=0;d_713co=0;d_717=0;d_717no=0;d_717co=0;d_719=0;
					d_813=0;d_813no=0;d_813co=0;d_817=0;d_817no=0;d_817co=0;d_819=0;
					d_913=0;d_913no=0;d_913co=0;d_917=0;d_917no=0;d_917co=0;d_919=0;				
					d_1113=0;d_1113no=0;d_1113co=0;d_1117=0;d_1117no=0;d_1117co=0;d_1119=0;
					d_1213=0;d_1213no=0;d_1213co=0;d_1217=0;d_1217no=0;d_1217co=0;d_1219=0;
					d_1313=0;d_1313no=0;d_1313co=0;d_1317=0;d_1317no=0;d_1317co=0;d_1319=0;
					d_1413=0;d_1413no=0;d_1413co=0;d_1417=0;d_1417no=0;d_1417co=0;d_1419=0;
					
					//khoi tao gia tri cho cac bien
					s_lkngvu=ds_Data3.Tables[0].Rows[j]["idnghiepvu"].ToString();
					s_lkmang=ds_Data3.Tables[0].Rows[j]["mang"].ToString();
					s_lktkno=ds_Data3.Tables[0].Rows[j]["tkno"].ToString();
					s_lktkco=ds_Data3.Tables[0].Rows[j]["tkco"].ToString();
					d_lkno=Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["no"].ToString());
					d_lkco=Convert.ToDecimal(ds_Data3.Tables[0].Rows[j]["co"].ToString());
					#endregion 

					#region kiem tra nguon do so lieu vao ds
					//kiem tra dk, do so lieu
					if(s_lkmang.Trim()=="0113" )
					{
						if(s_lktkno.Trim()!="" || s_lktkco.Trim()!="")
						{
							//hoat dong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_309+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66121"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_307no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66111") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66121")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_307co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46111") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_303co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_303no+=d_lkno;
							d_303=d_303co-d_303no;
							d_307=d_307no-d_307co;							

							//hoat dong khong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_319+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66122"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_317no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66112") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66122")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_317co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46112") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_313co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_313no+=d_lkno;
							d_313=d_313co-d_313no;
							d_317=d_317no-d_317co;

							//du an
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && (s_lkngvu=="8" || s_lkngvu=="7"))
								d_309_+=d_lkno;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_307no_+=d_lkno;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_307co_+=d_lkco;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_303co_+=d_lkco;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_303no_+=d_lkno;
							d_303_=d_303co_-d_303no_;
							d_307_=d_307no_-d_307co_;
							
						}
					}
					else
						if(s_lkmang.Trim()=="0114")
					{
						if(s_lktkno.Trim()!="" || s_lktkco.Trim()!="")
						{
							//hoat dong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_409+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66121"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_407no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66111") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66121")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_407co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46111") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_403co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_403no+=d_lkno;
							d_403=d_403co-d_403no;
							d_407=d_407no-d_407co;

							//hoat dong khong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_419+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66122"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_417no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66112") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66122")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_417co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46112") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_413co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_413no+=d_lkno;
							d_413=d_413co-d_413no;
							d_417=d_417no-d_417co;

							//du an 
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462"&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_409_+=d_lkno;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662"&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_407no_+=d_lkno;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_407co_+=d_lkco;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_403co_+=d_lkco;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_403no_+=d_lkno;
							d_403_=d_403co_-d_403no_;
							d_407_=d_407no_-d_407co_;
						}
					}
					else
						if(s_lkmang.Trim()=="02121")
					{
						if(s_lktkno.Trim()!="" || s_lktkco.Trim()!="")
						{
							//hoat dong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_509+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66121"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_507no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66111") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66121")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_507co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46111") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_503co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_503no+=d_lkno;
							d_503=d_503co-d_503no;
							d_507=d_507no-d_507co;

							//hoat dong khong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_519+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66122"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_517no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66112") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66122")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_517co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46112") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_513co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_513no+=d_lkno;
							d_513=d_513co-d_513no;
							d_517=d_517no-d_517co;

							//du an
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462"&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_509_+=d_lkno;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662"&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_507no_+=d_lkno;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_507co_+=d_lkco;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_503co_+=d_lkco;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_503no_+=d_lkno;
							d_503_=d_503co_-d_503no_;
							d_507_=d_507no_-d_507co_;
						}
					}
					else 
						if(s_lkmang.Trim()=="02122")
					{
						if(s_lktkno.Trim()!="" || s_lktkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_609+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66121"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_607no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66111") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66121")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_607co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46111") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_603co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_603no+=d_lkno;
							d_603=d_603co-d_603no;
							d_607=d_607no-d_607co;

							//hoat dong khong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_619+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66122"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_617no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66112") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66122")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_617co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46112") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_613co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_613no+=d_lkno;
							d_613=d_613co-d_613no;
							d_617=d_617no-d_617co;

							//du an
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462"&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_609_+=d_lkno;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662"&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_607no_+=d_lkno;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_607co_+=d_lkco;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_603co_+=d_lkco;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_603no_+=d_lkno;
							d_603_=d_603co_-d_603no_;
							d_607_=d_607no_-d_607co_;
						}
					}
					if(s_lkmang.Trim()=="02123")
					{
						if(s_lktkno.Trim()!="" || s_lktkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_709+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66121"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_707no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66111") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66121")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_707co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46111") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_703co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_703no+=d_lkno;
							d_703=d_703co-d_703no;
							d_707=d_707no-d_707co;

							//hoat dong khong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_719+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66122"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_717no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66112") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66122")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_717co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46112") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_713co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_713no+=d_lkno;
							d_713=d_713co-d_713no;
							d_717=d_717no-d_717co;

							//du an
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462"&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_709_+=d_lkno;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662"&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_707no_+=d_lkno;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_707co_+=d_lkco;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_703co_+=d_lkco;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_703no_+=d_lkno;
							d_703_=d_703co_-d_703no_;
							d_707_=d_707no_-d_707co_;
						}
					}
					else
						if(s_lkmang.Trim()=="0214")
					{
						if(s_lktkno.Trim()!="" || s_lktkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_809+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66121"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_807no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66111") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66121")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_807co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46111") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_803co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_803no+=d_lkno;
							d_803=d_803co-d_803no;
							d_807=d_807no-d_807co;

							//hoat dong khong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_819+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66122"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_817no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66112") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66122")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_817co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46112") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_813co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_813no+=d_lkno;
							d_813=d_813co-d_813no;
							d_817=d_817no-d_817co;

							//du an
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462"&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_809_+=d_lkno;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662"&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_807no_+=d_lkno;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_807co_+=d_lkco;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_803co_+=d_lkco;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_803no_+=d_lkno;
							d_803_=d_803co_-d_803no_;
							d_807_=d_807no_-d_807co_;
						}
					}
					else
						if(s_lkmang.Trim()=="0218")
					{
						if(s_lktkno.Trim()!="" || s_lktkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_909+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66121"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_907no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66111") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66121")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_907co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46111") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_903co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_903no+=d_lkno;
							d_903=d_903co-d_903no;
							d_907=d_907no-d_907co;

							//hoat dong khong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_919+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66122"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_917no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66112") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66122")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_917co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46112") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_913co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_913no+=d_lkno;
							d_913=d_913co-d_913no;
							d_917=d_917no-d_917co;

							//du an
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462"&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_909_+=d_lkno;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662"&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_907no_+=d_lkno;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_907co_+=d_lkco;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_903co_+=d_lkco;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_903no_+=d_lkno;
							d_903_=d_903co_-d_903no_;
							d_907_=d_907no_-d_907co_;
						}
					}				
					else
						if(s_lkmang.Trim()=="0401")
					{
						if(s_lktkno.Trim()!="" || s_lktkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_1109+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66121"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1107no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66111") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66121")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1107co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46111") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_1103co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_1103no+=d_lkno;
							d_1103=d_1103co-d_1103no;
							d_1107=d_1107no-d_1107co;

							//hoat dong khong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_1119+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66122"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1117no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66112") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66122")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1117co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46112") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_1113co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_1113no+=d_lkno;
							d_1113=d_1113co-d_1113no;
							d_1117=d_1117no-d_1117co;

							//du an
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462"&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_1109_+=d_lkno;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662"&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1107no_+=d_lkno;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1107co_+=d_lkco;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_1103co_+=d_lkco;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_1103no_+=d_lkno;
							d_1103_=d_1103co_-d_1103no_;
							d_1107_=d_1107no_-d_1107co_;
						}
					}
					else
						if(s_lkmang.Trim()=="0501")
					{
						if(s_lktkno.Trim()!="" || s_lktkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_1209+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66121"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1207no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66111") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66121")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1207co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46111") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_1203co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_1203no+=d_lkno;
							d_1203=d_1203co-d_1203no;
							d_1207=d_1207no-d_1207co;

							//hoat dong khong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_1219+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66122"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1217no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66112") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66122")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1217co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46112") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_1213co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_1213no+=d_lkno;
							d_1213=d_1213co-d_1213no;
							d_1217=d_1217no-d_1217co;

							//du an
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462"&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_1209_+=d_lkno;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662"&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1207no_+=d_lkno;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1207co_+=d_lkco;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_1203co_+=d_lkco;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_1203no_+=d_lkno;
							d_1203_=d_1203co_-d_1203no_;
							d_1207_=d_1207no_-d_1207co_;
						}
					}
					else
						if(s_lkmang.Trim()=="0402")
					{
						if(s_lktkno.Trim()!="" || s_lktkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_1309+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66121"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1307no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66111") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66121")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1307co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46111") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_1303co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_1303no+=d_lkno;
							d_1303=d_1303co-d_1303no;
							d_1307=d_1307no-d_1307co;

							//hoat dong khong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_1319+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66122"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1317no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66112") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66122")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1317co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46112") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_1313co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_1313no+=d_lkno;
							d_1313=d_1313co-d_1313no;
							d_1317=d_1317no-d_1317co;

							//du an
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462"&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_1309_+=d_lkno;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662"&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1307no_+=d_lkno;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1307co_+=d_lkco;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_1303co_+=d_lkco;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_1303no_+=d_lkno;
							d_1303_=d_1303co_-d_1303no_;
							d_1307_=d_1307no_-d_1307co_;
						}
					}
					else
						if(s_lkmang.Trim()=="0502")
					{
						if(s_lktkno.Trim()!="" || s_lktkco.Trim()!="")
						{
							//hoat dong thuong xuyen 
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_1409+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66121"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1407no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66111") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66121")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1407co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46111") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_1403co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46111") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46121")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_1403no+=d_lkno;
							d_1403=d_1403co-d_1403no;
							d_1407=d_1407no-d_1407co;

							//hoat dong khong thuong xuyen
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122"))&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_1419+=d_lkno;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="66122"))&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1417no+=d_lkno;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66112") ||(s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="66122")) && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1417co+=d_lkco;
							if(((s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46112") || (s_lktkco.Trim().Length>=5 && s_lktkco.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_1413co+=d_lkco;
							if(((s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46112") || (s_lktkno.Trim().Length>=5 && s_lktkno.Trim().Substring(0,5)=="46122")) && s_lkngvu!="8" && s_lkngvu!="7")
								d_1413no+=d_lkno;
							d_1413=d_1413co-d_1413no;
							d_1417=d_1417no-d_1417co;

							//du an
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462"&& (s_lkngvu=="8" || s_lkngvu=="7"))
								d_1409_+=d_lkno;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662"&& s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1407no_+=d_lkno;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662" && s_lkngvu!="8"&&s_lkngvu!="7")	
								d_1407co_+=d_lkco;
							if(s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_1403co_+=d_lkco;
							if(s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462" && s_lkngvu!="8" && s_lkngvu!="7")
								d_1403no_+=d_lkno;
							d_1403_=d_1403co_-d_1403no_;
							d_1407_=d_1407no_-d_1407co_;
						}
					}
					#endregion 
					
					string phanloai="";
					if(((s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="462")|| (s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="662"))
						|| ((s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="462")|| (s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="662")))
					{
						ds_Data3.Tables[0].Rows[j]["phanloai"]="II";
						phanloai=ds_Data3.Tables[0].Rows[j]["phanloai"].ToString();
					}
					else
						if(((s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="461")|| (s_lktkno.Trim().Length>=3 && s_lktkno.Trim().Substring(0,3)=="661"))
						|| ((s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="461")|| (s_lktkco.Trim().Length>=3 && s_lktkco.Trim().Substring(0,3)=="661")))
					{
						ds_Data3.Tables[0].Rows[j]["phanloai"]="I";
						phanloai=ds_Data3.Tables[0].Rows[j]["phanloai"].ToString();
					}
					#region add row vao table

					//hoat dong
					ds_Data3.Tables[0].Rows[j]["d303"]=d_303;
					ds_Data3.Tables[0].Rows[j]["d307"]=d_307;
					ds_Data3.Tables[0].Rows[j]["d309"]=d_309;

					ds_Data3.Tables[0].Rows[j]["d313"]=d_313;
					ds_Data3.Tables[0].Rows[j]["d317"]=d_317;
					ds_Data3.Tables[0].Rows[j]["d319"]=d_319;

					ds_Data3.Tables[0].Rows[j]["d403"]=d_403;
					ds_Data3.Tables[0].Rows[j]["d407"]=d_407;
					ds_Data3.Tables[0].Rows[j]["d409"]=d_409;

					ds_Data3.Tables[0].Rows[j]["d413"]=d_413;
					ds_Data3.Tables[0].Rows[j]["d417"]=d_417;
					ds_Data3.Tables[0].Rows[j]["d419"]=d_419;

					ds_Data3.Tables[0].Rows[j]["d503"]=d_503;
					ds_Data3.Tables[0].Rows[j]["d507"]=d_507;
					ds_Data3.Tables[0].Rows[j]["d509"]=d_509;

					ds_Data3.Tables[0].Rows[j]["d513"]=d_513;
					ds_Data3.Tables[0].Rows[j]["d517"]=d_517;
					ds_Data3.Tables[0].Rows[j]["d519"]=d_519;

					ds_Data3.Tables[0].Rows[j]["d603"]=d_603;
					ds_Data3.Tables[0].Rows[j]["d607"]=d_607;
					ds_Data3.Tables[0].Rows[j]["d609"]=d_609;

					ds_Data3.Tables[0].Rows[j]["d613"]=d_613;
					ds_Data3.Tables[0].Rows[j]["d617"]=d_617;
					ds_Data3.Tables[0].Rows[j]["d619"]=d_619;

					ds_Data3.Tables[0].Rows[j]["d703"]=d_703;
					ds_Data3.Tables[0].Rows[j]["d707"]=d_707;
					ds_Data3.Tables[0].Rows[j]["d709"]=d_709;

					ds_Data3.Tables[0].Rows[j]["d713"]=d_713;
					ds_Data3.Tables[0].Rows[j]["d717"]=d_717;
					ds_Data3.Tables[0].Rows[j]["d719"]=d_719;

					ds_Data3.Tables[0].Rows[j]["d803"]=d_803;
					ds_Data3.Tables[0].Rows[j]["d807"]=d_807;
					ds_Data3.Tables[0].Rows[j]["d809"]=d_809;

					ds_Data3.Tables[0].Rows[j]["d813"]=d_813;
					ds_Data3.Tables[0].Rows[j]["d817"]=d_817;
					ds_Data3.Tables[0].Rows[j]["d819"]=d_819;

					ds_Data3.Tables[0].Rows[j]["d903"]=d_903;
					ds_Data3.Tables[0].Rows[j]["d907"]=d_907;
					ds_Data3.Tables[0].Rows[j]["d909"]=d_909;

					ds_Data3.Tables[0].Rows[j]["d913"]=d_913;
					ds_Data3.Tables[0].Rows[j]["d917"]=d_917;
					ds_Data3.Tables[0].Rows[j]["d919"]=d_919;					

					ds_Data3.Tables[0].Rows[j]["d1103"]=d_1103;
					ds_Data3.Tables[0].Rows[j]["d1107"]=d_1107;
					ds_Data3.Tables[0].Rows[j]["d1109"]=d_1109;

					ds_Data3.Tables[0].Rows[j]["d1113"]=d_1113;
					ds_Data3.Tables[0].Rows[j]["d1117"]=d_1117;
					ds_Data3.Tables[0].Rows[j]["d1119"]=d_1119;

					ds_Data3.Tables[0].Rows[j]["d1203"]=d_1203;
					ds_Data3.Tables[0].Rows[j]["d1207"]=d_1207;
					ds_Data3.Tables[0].Rows[j]["d1209"]=d_1209;

					ds_Data3.Tables[0].Rows[j]["d1213"]=d_1213;
					ds_Data3.Tables[0].Rows[j]["d1217"]=d_1217;
					ds_Data3.Tables[0].Rows[j]["d1219"]=d_1219;

					ds_Data3.Tables[0].Rows[j]["d1303"]=d_1303;
					ds_Data3.Tables[0].Rows[j]["d1307"]=d_1307;
					ds_Data3.Tables[0].Rows[j]["d1309"]=d_1309;

					ds_Data3.Tables[0].Rows[j]["d1313"]=d_1313;
					ds_Data3.Tables[0].Rows[j]["d1317"]=d_1317;
					ds_Data3.Tables[0].Rows[j]["d1319"]=d_1319;

					ds_Data3.Tables[0].Rows[j]["d1403"]=d_1403;
					ds_Data3.Tables[0].Rows[j]["d1407"]=d_1407;
					ds_Data3.Tables[0].Rows[j]["d1409"]=d_1409;

					ds_Data3.Tables[0].Rows[j]["d1413"]=d_1413;
					ds_Data3.Tables[0].Rows[j]["d1417"]=d_1417;
					ds_Data3.Tables[0].Rows[j]["d1419"]=d_1419;

					//du an
					ds_Data3.Tables[0].Rows[j]["d303_"]=d_303_;
					ds_Data3.Tables[0].Rows[j]["d307_"]=d_307_;
					ds_Data3.Tables[0].Rows[j]["d309_"]=d_309_;

					ds_Data3.Tables[0].Rows[j]["d403_"]=d_403_;
					ds_Data3.Tables[0].Rows[j]["d407_"]=d_407_;
					ds_Data3.Tables[0].Rows[j]["d409_"]=d_409_;

					ds_Data3.Tables[0].Rows[j]["d503_"]=d_503_;
					ds_Data3.Tables[0].Rows[j]["d507_"]=d_507_;
					ds_Data3.Tables[0].Rows[j]["d509_"]=d_509_;

					ds_Data3.Tables[0].Rows[j]["d603_"]=d_603_;
					ds_Data3.Tables[0].Rows[j]["d607_"]=d_607_;
					ds_Data3.Tables[0].Rows[j]["d609_"]=d_609_;

					
					ds_Data3.Tables[0].Rows[j]["d703_"]=d_703_;
					ds_Data3.Tables[0].Rows[j]["d707_"]=d_707_;
					ds_Data3.Tables[0].Rows[j]["d709_"]=d_709_;

					ds_Data3.Tables[0].Rows[j]["d803_"]=d_803_;
					ds_Data3.Tables[0].Rows[j]["d807_"]=d_807_;
					ds_Data3.Tables[0].Rows[j]["d809_"]=d_809_;

					ds_Data3.Tables[0].Rows[j]["d903_"]=d_903_;
					ds_Data3.Tables[0].Rows[j]["d907_"]=d_907_;
					ds_Data3.Tables[0].Rows[j]["d909_"]=d_909_;

					ds_Data3.Tables[0].Rows[j]["d1103_"]=d_1103_;
					ds_Data3.Tables[0].Rows[j]["d1107_"]=d_1107_;
					ds_Data3.Tables[0].Rows[j]["d1109_"]=d_1109_;
					
					ds_Data3.Tables[0].Rows[j]["d1203_"]=d_1203_;
					ds_Data3.Tables[0].Rows[j]["d1207_"]=d_1207_;
					ds_Data3.Tables[0].Rows[j]["d1209_"]=d_1209_;

					
					ds_Data3.Tables[0].Rows[j]["d1303_"]=d_1303_;
					ds_Data3.Tables[0].Rows[j]["d1307_"]=d_1307_;
					ds_Data3.Tables[0].Rows[j]["d1309_"]=d_1309_;

					
					ds_Data3.Tables[0].Rows[j]["d1403_"]=d_1403_;
					ds_Data3.Tables[0].Rows[j]["d1407_"]=d_1407_;
					ds_Data3.Tables[0].Rows[j]["d1409_"]=d_1409_;

					#endregion
				}
			}
			
			if(ds_Data3!=null)
				ds_Data.Merge(ds_Data3);
			ds_Data.AcceptChanges();
			try
			{
				if(flag_dsnull)return null;
				else 
					ds_Data.WriteXml("D:\\kinhphiI.xml",XmlWriteMode.WriteSchema);
			}
			catch{}
			return ds_Data;
		}
		#endregion
		#region Dong tat ca cac ket noi va dataset khi ket thuc form

		public void Dispose()
		{
			try
			{
				ds_Data.Dispose();
			}
			catch{};
		}
		
		#endregion
		
	}
}
